Fog Creek Software
Discussion Board

2 numbers

2 integer numbers, each of them is larger than 1 and less than 50. F. knows their sum. G. knows their product. This is the dialog between them:
F.: "I don't know what these numbers are"
G.: "I don't know what these numbers are".
F.: "I knew you couldn't know what they were".
G.: "Well, now I know what they are"
F.: "And I know too"

Question: what were these numbers?

Thursday, August 28, 2003

what kind of a q'n is this?

Thursday, September 11, 2003

A puzzle, obviously.

Given a number's sum, and its product, you can usually find out what the numbers are. a+b = 27, ab = 300 => a + 300/a = 27, and a^2 - 27 a + 300 = 0, giving a = 15 or 12, and b the other one.

So let's look at the puzzle
F knows their sum, but can't tell what the numbers are. That means that 4, 5, 97 and 98 are ruled out as the sum. (2,2), (2,3), (49,48), (49,49) are ruled out as numbers. But it doesn't really give us a huge amount of info.

G knows their product, and given the information he has, can't tell what the numbers are. We can rule out lots of numbers - the numbers which can only be produced one way multiplying numbers between 1 and 50. So we can rule out 3, 5, 7 (in fact, all the primes), and the composite numbers made from multiplying 2 primes (such as 91). We're left with all the composite numbers with 3 or more prime factors. That is a much smaller set than all the possible factors, with perhaps a hundred numbers in it.

The F says "I knew you couldn't tell". Ah. With his a+b, he knows the possible values of ab - say a+b = 12, then ab = 20, 27, 32, 35, 36.

Now F could only have said he knew G didn't know if all those possibilities had more than 3 prime factors. In this case, if the product had been 35, then G would have known the numbers were 5 and 7. So this reduces further the possible numbers. We need to find all the numbers between 4 and 98 with all possible sums in {2,49} giving products with 3 or more factors. There can't be too many.

Then G says "Aha, now I know". Given that F *doesn't* know what the answer is at this stage, and in addition that he's told us he knew we couldn't know, we can then generate, from the product that we have, all the possible sums, and for each of those sums do the calculation that F did above. We then eliminate in the same way that F did, and we can assume that only one will be left. Otherwise, we wouldn't know what the numbers were :)

Then F says 'aha, now I know". We can then say that if G knows from the list we got in the last step, then from the list of pairs we got in our last step, for each of them there was only one which could give G his answer, and we run through our list doing the same thing G did in the last step. There are probably several possibilities for the product for a few of the sums, and only one of them with a unique answer.

Anyway, this is more or less a how-to-solve, rather than a solution. Narrowing down to the products of >= 3 primes is the hard part, and would take ages. The rest is just slogging.

Dave Neary
Wednesday, September 17, 2003

Answering the victim's question: this is one of the best puzzles I know :) Just from this dialog - almost no information at all - it's possible to say what the numbers are. Isn't it amazing?

Dave, you are absolutely right in saying that it is possible to limit the possible set of pairs. But the path you are suggesting is too hard for a human :) Of course, this puzzle can be translated to: write a program that will find these numbers - in this case your approach is perfect because it allows to come with algorithm. But it is possible to find a solution that doesn't require a computer, by just properly reasoning from the rules we know from this dialog until we limit the possible set of pairs to only 1 pair of numbers :)

Thursday, September 18, 2003

so easy .. take me 45 min to solve it.. the answer is 3 and 4. just solve use regular way of math~!

Ping Li
Sunday, October 5, 2003

the answers is 3 and 4. why?
3 + 4 = 7 and the first guy know sum which is 7 will have two choice (2+5) and (3+4)
3 * 4 = 12 and the second guy know product which is 12 will have two choice (2 * 6) and (3 * 4)

dont need to do so much things just use some normal math to solve the begining part is below..

x and y are two integer, and S is sum and P is product are known by each one person
we know x and y is range of 2 to 49, S < P
1. x + y = S => x = S - y
2. xy = P
1 and 2 => y^2 - Sy + P = 0 and then use the formula (-b +/- Square root of (b^2 - 4ac))/2a u will find lot of information on the numbers...........

Ping Li
Sunday, October 5, 2003

I think 3 & 4 is wrong. Here is why. Let's assume that the numbers were 3 & 4:

F sees 7 as the sum, but doesn't know if the numbers are 3+4 or 5+2. He knows that the product will be either 12 or 10. F announces that he doesn't know what the numbers are.

G sees 12, which can be 6*2 or 3*4, so he says that he doesn't know what the numbers are.

F considers G's statement. If the numbers were 5+2, then G would see 10, which has only one pair of factors, and G would know what they were. F would now know what the numbers were, and would not make his next statement because a) he would now know the numbers and b) it's not true that he knew G wouldn't know what the numbers were.

Back to the drawing board.

David Clayworth
Monday, October 6, 2003

THE Whole idea

we assume F knows sum is 7, and this only sum from (3,4) and (2,5)
so he say he dont know the answer for it coz 2 choice
G knows the product is 12 and this is only (3x4) and (2x6)
and he say he dont know the answer for it coz 2 choice
and When F say "I knew you couldn't know what they were".
Then G assume F know (3,4)sum only 7 which has 3+4, 2+5 or (2,6)sum only 8 which has 2+6, 4+4, 3+5
G knows if product(2,5)=10 (3,5)=15 he will know the answer right away. he think If F got a sum of 8, no matter if he knows the answer or not, F wont know it. So, G answer : now i know, but actually he still dont know..
Then F heard what G said, He know it.. then he can sure the answer will be (3,4)
and G heard F say he know it too, then he now can sure the answer will be (3,4)

PS: THIS question include psychology too

Ping Li
Monday, October 6, 2003

add: if G really knows the number before F, then F dont really need to have the last statement out for G to listen to which is F.: "And I know too"

Ping Li
Monday, October 6, 2003

Ping Li, I'm assuming that both people are telling the truth, and not competing with each other. If they are not telling the truth then there is no point to the question, because the numbers might be 2 & 3 and F and G are just lying about whether they know the answer or not.

David Clayworth
Tuesday, October 7, 2003

2, 3 is impossible coz sum of 5.. u can know the number right away. the 2 integer is bigger than " 1 ", which at least 2.  Also in the question, it didnt tell you if they are telling truth or not. So if u make the assumption yourself, then it wont be logical.. and also, by the information that limited in the formula that i am given above. u will be take out lot of the sets. and the only set that fit in this dialog will left with 3,4..

the logic in here is
F.: "I don't know what these numbers are"
G.: "I don't know what these numbers are".
truth or not, dont know..
F.: "I knew you couldn't know what they were".
truth, it actually just repeat what G was telling F. in last statement. and testify if G lie or not.
G.: "Well, now I know what they are"
G say now he know.. and you cant tell if it is truth or not. coz it is conflict with what statement he made before. just by what F said "I knew you couldn't know what they were",but at this point. G make this statment can give F some idea... and G can testify by F's answer later if it is (3,4) or (2,6) if F answer he still dont know, then the answer will be (2,6), but if F say knows the answer, then G will know the answer be (3,4)
F.: "And I know too"
F found the answers on that G didnt lie on the second statment by G said"Well, now" two words. so he can sure the number will be (3,4), but not (2, 5)

But G heard F say he now know it.. then, the only choice that F will be know is (3,4) but he dont need to make an other statments. ^^

if ur guys not accept this logic.. then ... need to ask the guy who made this question.. i think he know the right answer!

Ping Li
Tuesday, October 7, 2003

oh btw, any other sets cant fit in this logic. coz will have too many variability

Ping Li
Tuesday, October 7, 2003

I think I have an answer for this.

I can't possibly begin to describe how I worked this out, but the answer is 4 and 13. Let's check this.

The sum is 17 and the product is 52. Obviously F's first statement is true. G's first statement is true because the numbers could be 4 & 13 or 2 & 26.

For ease of explanation later lets create a set of numbers. These are the numbers for which, for all the pairs of numbers that add up to that number, none of the pairs are made up of two primes. We will call the set 'F2-compliant' numbers.

F's second statement is true because of all the possible numbers that could sum to 17, none of them are a pair of primes, so he knows that G is looking at a product with more than 1 factorisation. From this statement we can decude that the sum F is looking at must be in the set of F2-compliant numbers.

G can see two possible factorisations. However he knows that 2+26 would sum to 28. When he hears F's second statement, he knows that F cannot make truthfully if the sum was 28; F would think the numbers might be 5 & 23, which are prime. However he knows that F could make the statement truthfully if F knew the sum was 17. Now G knows the sum is 17, and hence knows the two numbers.

On hearing G's second statement F now looks at the pairs of numbers that could possibly add to 17. Considering all the possible products, he sees that for each has factor pairs that sum to non-F2 compliant numbers, and in all but one case there are two factor pairs that do this. The one case is 4+13, which has a product of 52 and thus possible factors of 4X13 (summing to 17, F2 compliant) and 2x26 (summing to 28, not F2 compliant). F now knows that the numbers are 4 & 13, so he makes his last statement.

I haven't checked that there are not other solutions.

David Clayworth
Wednesday, October 8, 2003

For the set of (4,13) will be right unless you make 2 assumptions a head: 1. The both guys are telling the 100%truth in the dialog. 2. the conversation take hell long time to talk, because some step they need to do some maths, or F is a genius that he can do all the maths in head for 2 sec~ between they are talking.

PS: for this dialog how long u think it will take for 2 people to speak? and also in a daily life, are you 100% sure the guy who is talking to you, tell you 100% truth? . for my idea of (3,4) u dont have to make any assumptions..

Ping Li
Wednesday, October 8, 2003

The answer is 1 and 4.  Do the logic; it works.  My whole office spent a day a couple years ago working this out; lost productivity but necessary in order to maintain our sanity. I actually posted this same question on this site back then.  Apparently it rolled off.  Thanks for putting it back up, Peter.

David Haner
Tuesday, November 11, 2003

Thats wrong since question said numbers are greater than 1.

Tuesday, November 11, 2003

I've worked it out comprehensively by computer. The answer is indeed 4 and 13.

I will have to go back and see how to do it easier...

Ham Fisted
Monday, November 17, 2003

*  Recent Topics

*  Fog Creek Home