Enigmatic Code

Programming Enigma Puzzles

Enigma 1351: Let’s face it

From New Scientist #2510, 30th July 2005

I took a large wooden cube and painted two of its faces red, two of its faces white, and its two remaining faces blue.

Then I cut up the cube into lots of identically sized smaller cubes and gave them to my niece to play with.

First she counted all the small cubes out loud “One, two, three…”. Then she counted the number of small cubes which had both at least one red face and at least one white face. Then she counted the number of small cubes which had at least one red face and at least one blue face but no white faces.

These last two answers were different but one was the reverse of the other.

How many small cubes have at least one white face but no red faces and no blue faces?

If found a few paper copies of New Scientist while tidying up. This puzzle is from one of them – it doesn’t seem to currently appear in either New Scientist’s or Google Books’ archives.

[enigma1351]

Advertisements

One response to “Enigma 1351: Let’s face it

  1. Jim Randell 13 March 2012 at 1:33 pm

    The following Python program runs in 38ms.

    from itertools import count
    
    # consider an n x n x n cube (n > 1)
    # with faces: UDFBLR
    faces = dict((f, i) for i, f in enumerate(list('UDFBLR')))
    
    # there are 8 corners:
    corners = 'UFL UFR UBL UBR DFL DFR DBL DBR'.split()
    
    # there are n-2 of each of 12 edges:
    edges = 'UF UL UR UB FL FR BL BR DF DL DR DB'.split()
    
    # possible colourings:
    #             UDFBLR UDFBLR UDFBLR UDFBLR UDFBLR
    colourings = 'rrwwbb rrwbwb rbwwrb rwwbrb rwbbrw'.split()
    
    # consider n x n x n cubes
    def solve(n):
      for c in colourings:
        # count the number of pieces that are:
        # 1: red, white
        # 2: red, blue, no white
        # 3: white, no red, no blue
        n1, n2, n3 = 0, 0, 2 * pow(n - 2, 2)
        for p in corners + edges:
          # how many are there of this piece?
          m = 1 if len(p) == 3 else n - 2
          # colour the piece
          pc = list(c[faces[f]] for f in list(p))
          if 'r' in pc:
            if 'w' in pc: n1 += m
            elif 'b' in pc: n2 += m
          elif 'w' in pc and not 'b' in pc: n3 +=m
    
        if n1 != n2 and n1 == int(str(n2)[::-1]):
          print(n, c, n1, n2, n3)
          return True
    
    for n in count(2):
      if solve(n): break
    

    Solution: There are 210 small cubes with only white painted faces.

    Note: This is the smallest solution – i.e. with the large cube cut into the smallest number of “cubelets” – the cube is cut into a 12 × 12 × 12 cube consisting of 1728 cubelets. Which must have taken Susan’s niece some time to count out loud.

    If you leave the program running you see that solutions exist for n × n × n cubes where n = 10^p + 2, for positive integers p. The solutions are all of the form 2×10^2p + 10^p, with 210 being the smallest (p=1), the next smallest (p=2), would have 20100 cubelets with only white painted faces, but the initial cube would have been cut into 102 × 102 × 102 = 1,061,208 cubelets, which would take even the most committed niece too long to count out loud.

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: