1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# the maximum cuboid side considered max_side = 30 d = dict() # a, b and c are the sides of the cuboid in non decreasing size for a in range(3, max_side): for b in range(a, max_side): for c in range(b, max_side): # the total number of cubes total = a * b * c # the number of unpainted (internal) cubes unpainted = (a - 2) * (b - 2) * (c - 2) # the number of cubes on edges (excluding corners) two_faces = 4 * (a + b + c - 6) # the number of cubes on faces (excluding edges and corners) one_face = total - unpainted - two_faces - 8 # unpainted cube number equals the number with two painted faces if unpainted == two_faces: d[(a, b, c)] = (unpainted, one_face, two_faces, total) # for Megan's cuboid for meg in d: # for Oliver's cuboid for oli in d: # Megan has more cubes and the difference equals Oliver's number # of unpainted cubes if d[meg][3] - d[oli][3] == d[oli][0]: fs = 'Megan has {} cubes with only one painted face.' print(fs.format(d[meg][1])) print("Megan's cube: {}, Oliver's cube: {}.".format(meg, oli)) |