All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Numbers
The Maths Wizard (Posted on 2023-11-15) Difficulty: 3 of 5
Tom, Dick, and Harry are the prisoners of the Maths Wizard. The Wizard shows them a box with each of the digits 1 through 9 exactly TWICE, and tells them he will place 6 of these 18 digits on each one's forehead to form a perfect square. Each person can see the numbers on the others' foreheads, but not on his own.

The Wizard announced, "I will set each of you free as soon as you can tell me the number on your forehead. Nobody is allowed to communicate with any other person in any way. You get only one guess each."

Tom, Dick, and Harry sat in silence for several hours, filling up pages of calculations. Getting bored, the Wizard said, "Hey, I had thought you were clever guys. All right, I'll give each one of you just one hint. Tom, the square root of your number is a palindrome. Dick, the square root of your number is not a palindrome. Harry, any two adjacent digits of your number differ at most by 3."

And then the Wizard's castle echoed, "GOT IT !!!" as they all shouted together.
What were the numbers on each person's forehead?

See The Solution Submitted by K Sengupta    
Rating: 5.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution No Subject Comment 1 of 1
6-digit squares have square roots from 317 to 999
Each person will know the 6 digits on his forehead but will not know the order.  In each case, there must be at least 2 permutations of those digits that form a square, but only one that satisfies the additional condition.

Candidates:
Tom    Dick   Harry
391876 195364 874225  reject
391876 351649 874225  reject
391876 395641 874225  reject
543169 139876 874225  This one is the answer

The first 3 are rejected because although tom and harry are unique, there are three potential values for dick.

-------------
digits = '123456789'*2
palsquares = []
nonpalsquares = []
differ3squares = []
digit_count_dict = {}
nonsingletons = []
tom = []
dick = []
harry = []

for n in range(317,1000):
    n2 = n**2
    sn = str(n2)
    digit_count = ''
    for char in '0123456789':
        digit_count += str(sn.count(char))

    if int(digit_count[0]) > 0:
        continue
    if int(max(digit_count)) > 2:
        continue
    
    if digit_count not in digit_count_dict:
        digit_count_dict[digit_count] = [n2]
    else:
        digit_count_dict[digit_count].append(n2)
        
    if isPalindrome(n):
        palsquares.append(n2)
    else:
        nonpalsquares.append(n2)
    diffs = ''
    for i,char in enumerate(sn):
        if i == 0:
            continue
        diffs += str( abs( int(sn[i]) - int(sn[i-1]) ) )
    if int(max(diffs)) <= 3:
        differ3squares.append(n2)

for d in digit_count_dict:
    if len(digit_count_dict[d]) > 1:
        for k in digit_count_dict[d]:
            if k in palsquares:
                tom.append(k)
            if k in nonpalsquares:
                dick.append(k)
            if k in differ3squares:
                harry.append(k)
print('Tom    Dick   Harry')
pattern = '0222222222'
for t in tom:
    for d in dick:
        for h in harry:
            tdh = str(t) + str(d) + str(h)
            tdhpattern = ''
            for char in '0123456789':
                tdhpattern += str(tdh.count(char))
            if tdhpattern == pattern:
                print(t,d,h)

  Posted by Larry on 2023-11-15 10:27:23
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (12)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information