# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1745: Cutting cubes

From New Scientist #2913, 20th April 2013 [link]

I have before me a number of solid cubes. I make a single straight cut through each of them, avoiding cutting through any of the vertices. The resulting solids have between them the same number of even-sided faces as odd-sided faces. The number of cubes I started with is the minimum compatible with the information given above.

How many cubes did I start with?

[enigma1745]

### 2 responses to “Enigma 1745: Cutting cubes”

1. Jim Randell 17 April 2013 at 8:35 pm

If I’ve found all the different ways to cut the cube, and calculated the number of even-sided and odd-sided faces correctly, this code should give the answer. Ideally I’d like the program to calculate the different slices and enumerate the faces, but that will be more work. On the plus side, it only takes 34ms to run.

```from itertools import count, combinations_with_replacement
from enigma import printf

# disparity between even-sided and odd-sides faces
#   v1+7/e3 v2+6/e4 v3+5/e5 v4+4/e4 v4+4/e6
D = (3 - 8,  8 - 4,  5 - 8, 12 - 0, 2 - 12)

def solve():
for n in count(1):
r = set(s for s in combinations_with_replacement(D, n) if sum(s) == 0)
if r: yield (n, r)

print(list((i + 1, d) for (i, d) in enumerate(D)))

for (n, r) in solve():
printf("{n} cubes {r}")
break
```

Solution: You started with 4 cubes.

2. arthurvause 17 April 2013 at 9:06 pm

If I have counted the correct number (not guaranteed) of even and odd faces from these diagrams:

```# Using the enumeration from
# http://www.learner.org/courses/learningmath/geometry/session9/solutions_c.html#c1
# slice a : 12 even, 0 odd
# slice b : 3 even, 8 odd
# slice c : 8 even, 4 odd
# slice e : 5 even,  8 odd
# slice f : 2 even, 12 odd

from itertools import product
num = range(14)

mincubes=1000
for a,b,c,e,f in product(num,num,num,num,num):
if 12*a + 3*b+8*c+5*e+2*f == 8*b+4*c+8*e+12*f \
and 0 < a+b+c+e+f < mincubes:
mincubes = a+b+c+e+f
sol = (a,b,c,e,f)

print mincubes, "cubes, (a,b,c,e,f)=", sol
```

This site uses Akismet to reduce spam. Learn how your comment data is processed.