Figure out the number I'm thinking of with a single question!
I'm thinking of a number amongst 1, 2, and 3. You are allowed to ask me a single question, to which I will truthfully answer with โyesโ, โnoโ, or โI don't knowโ.
How can you find out the number I picked?
Give it some thought!
If you need any clarification whatsoever, feel free to ask in the comment section below.
(I originally found this puzzle on Reddit.)
Know how to solve this? Be the first to join the list of solvers by emailing me your solution!
Congratulations to the ones that solved this problem correctly and, in particular, to the ones who sent me their correct solutions:
Join the list of solvers by emailing me your solution!
Lots of people sent in their solutions and I was very pleased with the amount of different solutions people came up with! Hence, the solution I present here is not the only one, but it's one I find very elegant.
The question you will ask me is
โIf I pick one of the other two numbers, is yours larger?โ
If I picked 3, then I know 3 is larger than any of the two other numbers (1 and 2). Therefore, I answer โYes.โ.
If I picked 1, then I know 1 is smaller than any of the two other numbers (2 and 3). Therefore, I answer โNo.โ.
If I picked 2, then I have no idea if you got 1 or 3, and that implies I need to reply โI don't know.โ.
That's a pretty elegant solution, isn't it?
Feel free to share alternative solutions in the comments!
Don't forget to subscribe to the newsletter to get bi-weekly problems sent straight to your inbox.
Get a daily drop of Python knowledge. A short, effective tip to start writing better Python code: more idiomatic, more effective, more efficient, with fewer bugs. Subscribe here.