Sunday Times Teaser 2598 – Die Hard
by Victor Bryant
Published: 8 July 2012Â (link)
I have placed three identical standard dice in a row on a table-top, leaving just eleven faces and an odd number of spots visible. Regarding each face as a digit (with, naturally enough, the five- spotted face being the digit 5, etc) from the front I can read a three-figure number along the vertical faces and another three-figure number along the top. Similarly, if I go behind the row I can read a three-figure number along the vertical faces and another three- figure number along the top. Of these four three-figure numbers, two are primes and two are different perfect squares.
What are the two squares?
One Comment
Leave one →
-
Brian Gladman permalink1234567891011121314151617181920212223242526272829303132333435363738394041424344from itertools import permutations, productfrom number_theory import Primes# Given the values on the first and second faces of a die# around a vertex, return the value on the third face. On# a western die the traversal is anti-clockwise if 'same'# is true, otherwise it is clockwise (this convention is# reversed for a chinese die).def die_third_face(first, second, same=True):if second in (first, 7 - first):raise ValueErrort, f = min(first, 7 - first), min(second, 7 - second)c1 = ((f - t) % 3 == (1 if same else 2))c2 = (first < 4) == (second < 4)v = t + f + 1return 7 - v if c1 == c2 else v# list all possible pairs of front and top face values on a normal dieperms = list(x for x in permutations(range(1, 7), 2) if sum(x) != 7)def solve():# consider the top and front faces of three dice in a rowfor (d1f, d1t), (d2f, d2t), (d3f, d3t) in product(perms, repeat=3):# compose the four numbers seen on the top and front facesnbrs = ( 100 * d1t + 10 * d2t + d3t,100 * d3t + 10 * d2t + d1t,100 * d1f + 10 * d2f + d3f,777 - (100 * d3f + 10 * d2f + d1f) )# check for two different perfect squaressq = tuple(x for x in nbrs if int(x ** 0.5) ** 2 == x)if len(sq) == 2 and sq[0] != sq[1]:# and two primespr = tuple(x for x in nbrs if x in Primes())if len(pr) == 2:# check for an odd number of visible dotsif sum((d1t + 7 + die_third_face(d1f, d1t),d2t + 7,d3t + 7 + die_third_face(d3t, d3f) )) % 2:yield (sq, pr)for sq, pr in set(solve()):print('Squares = {}, Primes = {}'.format(sq, pr))