by ninjinxo · 4y ago · 0 comments
Two numbers are chosen randomly, both are positive integers smaller than 100. Sandy is told the sum of the numbers, while Peter is told the product of the numbers.
Then, this dialog occurs between Sandy and Peter:
Peter: I don't know the numbers.
Sandy: I don't know the numbers.
Peter: I don't know the numbers.
Sandy: I don't know the numbers.
Peter: I don't know the numbers.
Sandy: I don't know the numbers.
Peter: I don't know the numbers.
Sandy: I don't know the numbers.
Peter: I don't know the numbers.
Sandy: I don't know the numbers.
Peter: I don't know the numbers.
Sandy: I don't know the numbers.
Peter: I don't know the numbers.
Sandy: I don't know the numbers.
Peter: I do know the numbers.
What are the numbers?
Source: https://www.reddit.com/r/math/comments/32opae/next_level_che...
Here is some python code that might be more revealing https://www.online-python.com/c5nAfLoIqr
A code review would be greatly appreciated!
I mean, obviously the extremes get eliminated right away, and then the primes, but then I have to track 10,000 number combinations.
You can actually WLOG away all pairs where the second element is larger than the first.
Also, the most common kind of pair I eliminated was actually due to the size constraint (ie, 98 * 99) or pairs of (1, prime) which I didn't actually realize would be a thing until I coded it up.
another variant:
Peter: If I divide by 4, I have remainder x Sandy: If I divide by 4, I have remainder y Peter: If I divide by 25, I have remainder a Sandy: If I divide by 25, I have remainder b Peter and Sandy (in unison): Got it!
x + y = s
x * y = p
x = s - y
x = p/y
substitute for x
p/y = s - y
p = sy - y*2
y*2 - sy + p = 0
# use the quadratic formula to solve for y
y = (-b ± √(b²-4ac)) / (2a)
In python:
import numpy as np
x = np.random.randint(1,100)
y = np.random.randint(1,100)
s = x+y
p = xy
a = 1
b = -1
sc = p
y_solved = (-1b + (b*2 - 4ac)*.5)/(2a),(-1b - (b*2 - 4ac)*.5)/(2a)
print(x,y,y_solved)
> Each sentence is extra data given to the other person.
> When Peter says "I don't know the numbers", means that he doesn't have enough information. For example, if the product of the numbers is 10, it could be (1,10) or (2,5). But if the product is 9801, then Peter would know the answer (99,99). Therefore, his first sentence reveals to Sandy that (99,99) isn't a possible answer. But even this extra data isn't enough for Sandy to know the answer, and she says so. Again, this is extra data for Peter, but , again, is not enough. This go back and forth until suddenly Peter gains enough information to find the answer.
Before Peter told Sandy he didn't know, only 4 sums could have been caused by a unique pair (198, 3, 2, and 197). Peter telling Sandy he doesn't know lets her rule out lots of pairs, and after doing so, there are 9 sums that would have a single pair remaining that hadn't been ruled out. For example, were the sum 165, Sandy could have concluded that the only possible pairing would be 69 and 96, since the other pairs that add up to that number (e.g., 74 and 91, 80 and 85, etc.) would have unique products that Peter would have known about. That she doesn't know the answer yet therefore tells Peter that 69 and 96 is not a possible pair. Were the product 6624, Peter would now know that the only possible remaining pair was 72 and 92, and he would know the answer. But since he didn't know the answer, now Sandy knows that it can't have been 72 and 92 either.
This crossing out continues until Peter realizes that 70 and 96 was not a viable pair, which lets him realize that the only other way to get 6720 was to have the numbers be 80 and 84, and he declares he knew the answer. [Assuming I got the correct number of rounds]
Sandy knows the sum and has now been told that Peter doesn't know the pair. If the sum had been 6, the following pairs are possible: (1+5) (3+3) (4+2), Peter has just ruled out (1x5) and (3x3), so Sandy would be able to narrow it down to (1,5) if the sum had been 6.
So when she tells Peter she can't narrow it down, it tells him that the pair isn't (4,2) either (among many others).
And if Peter's number were 8: (1x8) or (2x4) he'd be able to solve it, but he doesn't so Sandy then knows that (1,8) isn't the solution either.