Two fun math puzzles

A few days ago, I saw a math puzzle in the old code farmer group, which reminded me of another problem with red eyes and blue eyes. I feel that it involves a bit of recursion and game meaning. Think about it carefully and share it with you.

Sum and Product

Sum and Product

Randomly choose two numbers, both positive integers less than 100. Sandy is told the sum of numbers, and Peter is told the product of numbers, and assuming both are sane enough, this conversation takes place 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. 

So what are these two numbers?

Don’t look at the screen for a few minutes ?

Note that the premise is that both people are smart and rational, and know how to extrapolate from the current situation.

There are a total of 4590 pairs of numbers from 1 to 100. Sandy said I don’t know , there is actually some information in it, because he knows the sum of two numbers, so he said I don’t know means it’s definitely not 1 + 1, 1 + 2 … this combination, because the sum of these combinations It is unique among these 4590 pairs of numbers. So Peter can rule out these combinations based on Sandy’s information.

Similarly, Peter can also exclude some combinations every time he says that I don’t know , and so on. If after seven rounds, Peter says that I know that combination, there will be an answer.

It’s easier to understand with the following Python program, sourced by Peter And Sandy :

 from collections import defaultdict # build pairs pairs = [ ] for i in range ( 1 , 100 ) : for j in range ( i , 100 ) : pairs . append ( ( i , j ) ) def singles_operation ( f ) : results = defaultdict ( list ) for a , b in pairs : results [ f ( a , b ) ] . append ( ( a , b ) ) singles = [ ] for ( k , value ) in results . items ( ) : # We want to return only the product/sum with one result because if # peter/sandy have this product/sum, then they'll know the two numbers if len ( value ) == 1 : singles . extend ( value ) # Sorted for readability return sorted ( singles , key = lambda x : x [ 0 ] ) def remove_products ( ) : singles = singles_operation ( lambda x , y : x * y ) print ( 'peter removed' , singles ) for s in singles : pairs . remove ( s ) def remove_sums ( ) : singles = singles_operation ( lambda x , y : x + y ) print ( 'sandy removed' , singles ) for s in singles : pairs . remove ( s ) for i in range ( 7 ) : remove_products ( ) remove_sums ( ) # This is the result because it returns the only pair with a product # not created by anything else left in the list. print ( 'result' , singles_operation ( lambda x , y : x * y ) )  

The red-eyed, blue-eyed paradox

This question was first said to be posted on the Internet by Tao Zhexuan, a Chinese math prodigy in Australia:

There are 100 people on an island, 5 with red eyes and 95 with blue eyes. This island has three strange religious rules.

  1. They can’t look in the mirror, they can’t see the color of their eyes.
  2. They can’t tell someone what color the other’s eyes are.
  3. Once someone knew his eye color, he had to kill himself that night .

Note: Although the title has 5 red eyes, the islanders do not know the exact number.

One day, a traveler came to this island. Since he didn’t know the rules here, he inadvertently said a word when he was partying with the whole island: You have red-eyed people here.

The final question: Assuming the people on this island are smart enough, everyone can make careful logical reasoning. What will happen to this island?

The problem is not simple, what the tourist said does not seem to provide any new information, but it can lead to strange results, because “everyone knows” and “everyone knows” is not the same as “everyone knows”.

Li Yongle’s explanation is very good, thanks to SedationH for recommending it to me in the comment area:

Do you really understand “The Emperor’s New Clothes”? What is the difference between knowing and speaking? Teacher Li Yongle talks about the power of “scream”

This article is reprinted from: http://catcoding.me/p/two-math-puzzles/
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment