# [Community Puzzle] Guessing digits

https://www.codingame.com/training/medium/guessing-digits

Created by @Jamproject,validated by @JBM,@crashtestdummy and @Jakque.
If you have any issues, feel free to ping them.

I donâ€™t get why it got so many downvotes, itâ€™s a nice puzzle.

1 Like

Continuing the discussion from [Community Puzzle] Guessing digits:

What mean " asks Burt if he knows a and b" - Burt try random or try find one by oneâ€¦
i use to for loop but it seems to be wrong idea.
I donâ€™t understand who find this a and b

The name is slightly misleading as guessing isnâ€™t allowed. They either know the exact digits or have to say they donâ€™t know. As they both start with different information saying that they donâ€™t know tells the other person something so at some point there is only one pair of digits or itâ€™s impossible.

2 Likes

Example: numbers are 2 and 5
Turn 1
Burt is given 7, there are multiple combinations that give a sum of 7 so he doesnâ€™t know which one.
Sarah is given 10, the only combination is 2*5 so she can find out.

Now, letâ€™s consider another example where Burt is given 7. If Sarah doesnâ€™t find the digits on turn 1, then Burt knows for sure that the combination is not (2, 5).

By filling a big chart with the history of what can be discovered at each turn, it kills possibilities turn after turn and some of them become findable at some point.

3 Likes

Indeed, itâ€™s a smart one. But it needs more explainations. Without yours, I would have skip the puzzle.

Hi,
I am having a hard time solving this puzzle, and I think I need a little bit more information. Here is what I understand after reading the problem description:

Maggie picks two digits `a` and `b` with 1 â‰¤ `a` â‰¤ 9, 1 â‰¤ `b` â‰¤ 9, and `a` â‰¤ `b`.

She writes their sum on a blue piece of paper, folds it, and says â€śHere is the sum of the two digits I choseâ€ť while handing it to Burt.

She then writes their product on a red piece of paper, folds it, and says â€śHere is the product of the two digits I choseâ€ť while handing it to Sarah.

Burt and Sarah do not share the contents of their respective pieces of paper.

The game is played in rounds.

In each round, Burt plays first by announcing his guess for (`a`, `b`), in this case (`n`, `m`).

• If Burt guesses right, the game ends with "(`n`,`m`) BURT `round number`"
• If Burt guesses wrong, then Sarah gets to announce her guess (`p`,`q`).
If she guessed correctly, the game ends with "(`p`,`q`) SARAH `round number`".
Otherwise, we proceed to the next round.

If any of the players is out of guesses when his/her turn comes, the game ends with â€śIMPOSSIBLEâ€ť.

Did I understand correctly?

1 Like

Not exactly, there are no â€śguessesâ€ť, either the player knows for sure what (a, b) is and tells it, or the players doesnâ€™t say anything and we move to the next player.

So a typical game would look more like this:

B: â€śI donâ€™t knowâ€ť
S: â€śI donâ€™t knowâ€ť
B: â€śI donâ€™t knowâ€ť
S: â€śI donâ€™t knowâ€ť
B: â€śI donâ€™t knowâ€ť
S: â€śI know, itâ€™s a = â€¦ and b = â€¦â€ť

Which might be a bit disturbing but thatâ€™s how it is ^^

1 Like

Ok, let me try again (-_-)>.

So before the game starts, let say ÎŹ is the set of possible pairs (`a`,`b`) such that 1 â‰¤ `a` â‰¤ 9, 1 â‰¤ `b` â‰¤ 9, and `a` â‰¤ `b`.
Maggie chooses an element (`a`, `b`) of ÎŹ and gives respectively the values `s` = `a` + `b` and `p` = `a` * `b` to Burt and Sarah.

Knowing `s`, Burt can narrow down ÎŹ to a subset S of possible solutions.
Sarah can also determine a subset P of ÎŹ from the value of `p`.

The game is played in rounds. In each round, Burt plays first.

If Burt is certain of knowing the answer |P| = 1 (i.e. P contains only one element) he announces it and the game ends, otherwise he passes his turn.
Sarah can then announce her answer if |S| = 1 or passes.
If both pass their turn, we proceed to the next round.

The fact that Burt/Sarah passes his/her turn should help his/her opponent further narrow down his/her set of possible solutions.

Am I getting warmer?

1 Like

Yes itâ€™s exactly that.
Itâ€™s all about â€śif it was a = â€¦, b = â€¦ he would have figured out by this turn and he didnâ€™t, so itâ€™s not that, letâ€™s remove this oneâ€ť.

1 Like

Gosh! I would have been really deep in the weeds, without your assistance.
Now that I have a better understanding of the basic premise of this puzzle, time for the hard partâ€¦solving it!
You saved me from a huge headache, thanks! (^_^)b

1 Like

Right, But the description doesnâ€™t say how Sarah and Burt proceed to guess the numbers. (random or trying for the minor number to the greater, or from the greater combination to the minor one).
Itâ€™ s the worst puzzle description I ever seen.