
When Is Cheryl's Birthday? - jonp
http://nbviewer.ipython.org/url/norvig.com/ipython/Cheryl.ipynb
======
gkoberger
Maybe I'm missing something, but the "hard" part of this problem is figuring
on the trick. Once you know that, it becomes relatively easy – and you can't
use a program to figure out the trick.

~~~
logicallee
I don't know, can code like this reason about knowledge-about-knowledge in
general?

For example, can a version of the code be used to solve the 'hardest puzzle' -

[https://xkcd.com/blue_eyes.html](https://xkcd.com/blue_eyes.html)

(solution: [https://xkcd.com/solution.html](https://xkcd.com/solution.html)) ?

~~~
malisper
It can.

If you know someone else doesn't know, that just gives you more knowledge you
yourself can use.

For the "hardest puzzle", on each day everyone learns that no one was able to
figure out the solution the day before. Because of this, a person knows that
for a possible number of blue-eyed people to be valid, a person who sees one
less blue eyed person than that, must have been unable to figure it out on the
previous day.

An Arc/Common Lisp solution I just wrote up:
[https://gist.github.com/malisper/80625bcda75c66780f81](https://gist.github.com/malisper/80625bcda75c66780f81)

~~~
logicallee
I don't have Lisp, can you link to a pastebin e.g. at
[https://ideone.com/](https://ideone.com/) that runs it?

------
ghurtado
I thought this was a great puzzle when I first saw it. IMHO, it is more
satisfying to "think through it" without paper and pencil, since it is
relatively simple to resolve.

The Python solution proposed is really great, in that it captures both the
expressive and functional spirit of the language.

~~~
ternaryoperator
>since it is relatively simple to solve

You are overestimating how simple it is.There are more than 1200 comments on
the solution on the NYTimes[1] almost all of them arguing that other dates are
correct.

[1] [http://www.nytimes.com/2015/04/15/science/answer-to-the-
sing...](http://www.nytimes.com/2015/04/15/science/answer-to-the-singapore-
math-problem-cheryl-birthday.html)

~~~
x0054
I have to admit, it took me more than 5 minutes to figure this one out, so if
this was a test problem, I probably failed. Maybe I am not as smart as I
think, but it's probably not as simple as people, including other comments to
this post, make it out to be. The trick to the problem is pretty obvious right
away, but what tripped me is improper perspective. Reading the comments on NY
Times, I think this is the same thing that trips up most people as well.

After eliminating May and June because they have unique days, which is
obvious, I got stuck trying to figure out how Albert would be able to figure
out the date after knowing that Bernard now knows the date. So I got stuck on
July 16, Aug. 15 and Aug. 17 for a while, because I could not figure out how
Albert would know the date if he was told August as the month. It took me a
few minutes (ok, like 5 or so, more then I care to admit to my self I suppose
:) ) to figure out that my job wasn't to figure out how Albert new, but rather
to figure out what the answer was IF Albert now knew the answer.

From that it's pretty easy, but it's the perspective that trips most people
up.

~~~
vacri
It wouldn't have taken you so long if you had've just been doing logic in a
classroom. This isn't a puzzle that was sprung on the students by surprise; it
was part of their course.

------
vessenes
This is just beautifully expressive python. I wouldn't think of using it this
way: writing

    
    
      return (not know(possible_dates)
              and all(not know(tell(Day(d)))
                        for d in possible_dates))
    

feels almost zen to me; or at least like Mr. Norvig likes himself some lisp at
times.

~~~
logicallee
Python: write pseudocode, and then make sure it's indented properly.

------
ibejoeb
Here's my quick solution in modern SQL. This is more expensive than it needs
to be, but doing it this way lets you see the truth table by commenting out
the final predicate.

fiddle:
[http://sqlfiddle.com/#!15/0c419/160/0](http://sqlfiddle.com/#!15/0c419/160/0)

gist:
[https://gist.github.com/ibejoeb/df57cb34bbe609293d6e](https://gist.github.com/ibejoeb/df57cb34bbe609293d6e)

------
zhte415
The problem with this problem, the way it was originally put, was the utterly
confusing English masked into a logic problem.

Write your specifications clearly, and then it does not become an
internationally shared 'problem' to solve.

[I work with insanely documented specifications just like this, year after
year. Not putting a problem clearly is not something to aspire to.]

~~~
baddox
Why do you think that confusion over the English description is more to blame
than the difficulties many people face with logic puzzles?

~~~
zhte415
I do not make a comparison to 'difficulties many people face with logic
problems' and did not make an assertion that many people face difficulties
with logic puzzles.

Getting back to the article: the problem is worded so badly it should be sent
back to the author to more coherently express what they think. Specifications,
etc...

~~~
sukilot
Or you could learn Singapore English and not demand that everyone translate
their work into your dialect.

------
tomp
For the more mathematically minded readers, here's a harder version of the
problem:

[http://jdh.hamkins.org/transfinite-epistemic-logic-puzzle-
ch...](http://jdh.hamkins.org/transfinite-epistemic-logic-puzzle-challenge/)

------
xarien
I'd have gone a different way since my setup and approach was a bit different
(I took a more visual approach). While this solution is elegant, it's also
incredibly hard to do in the real world as it requires far too much knowledge
to properly assign the "correct" definitions. It's no different than having a
perfect health heuristic land on your lap.

When I did this a while back, my approach was to construct a 5x4 matrix with
blanks (5 unique dates x 4 unique months). This allowed the clues to cross off
entire rows and or columns until only 1 pair stood standing. Personally, I
find the construction of the solution much more interesting than the problem
itself given how many people participated.

------
picardo
I'd be interested in seeing a solution in Prolog.

~~~
sigterm
it was posted here before:

[https://news.ycombinator.com/item?id=9395604](https://news.ycombinator.com/item?id=9395604)

~~~
shele
Thanks

------
zaroth
My own contribution from last week:

[https://news.ycombinator.com/item?id=9398638](https://news.ycombinator.com/item?id=9398638)

[http://opine.me/discovering-a-new-fizzbuzz/](http://opine.me/discovering-a-
new-fizzbuzz/)

------
john_butts
1\. HN comment about some aspect of fizzbuzz or whatever. Not how to solve
fizzbuzz or whatever; rather, some insight into how people solve problems,
which is the interesting part of the question. 2\. Two dozen oblivious nerds
tell u how to do it in 20 characters of perl

~~~
Gigablah
Are you offended that people are sharing their knowledge?

------
Fando
Maybe someone already mentioned this, but this problem is a simplified
formulation of a famous number thoery riddle called 'The Sum and Product
Riddle' which is even more baffling. Here it is
[http://blog.computationalcomplexity.org/2007/01/sum-and-
prod...](http://blog.computationalcomplexity.org/2007/01/sum-and-product-
riddle.html?m=1)

------
janhaak
This is quite disturbing for me. My Aunt's name is Cheryl. Her husband,
Bernard. Guess his brother's name!

~~~
sgentle
At first I don't know his brother's name, but I know now.

------
_asummers
Where can I find more puzzles of this flavor? This generated some fun
discussion on my Facebook wall.

~~~
bentcorner
I don't know where to find a general place of more puzzles like this, but
here's one I enjoyed:

[http://www.xkcd.com/blue_eyes.html](http://www.xkcd.com/blue_eyes.html)

------
mattbeckman
Friend of mine wrote a Scala solution: [http://www.agileatwork.com/scala-
solution-to-cheryls-birthda...](http://www.agileatwork.com/scala-solution-to-
cheryls-birthday-problem/)

------
Nursie
If you're puzzling over this you've done it wrong.

There is no inference from silence. There is no humanity in such a question,
there is simply the information you're given and the application of logic to
narrow down the answers. The Singaporean kids that took the exam knew this and
anyone that's ever taken a maths or logic exam should know this.

You don't guess what might have happened from human behaviour because you
don't know, you don't look for a 'trick' to give away the answer, you simply
use the data in the question to narrow down the possibilities until you can
arrive at an answer.

The moment you think "but what if this action could have taken place because
if he knew he would have said" you have failed.

And you probably suck at debugging.

------
kyberias
Couldn't resist. This is the solution ported to C#:

[https://github.com/kyberias/cherylsharp](https://github.com/kyberias/cherylsharp)

~~~
baronofcheese
Funny you say it. I had a go at it as well. Seems like we ended up more or
less the same :)

[https://gist.github.com/Cheesebaron/f813576f62dce8391c3b](https://gist.github.com/Cheesebaron/f813576f62dce8391c3b)

------
haddr
still looking for solution using RDF/OWL logical reasoning...

the python solution is neat, but i have a feeling that there are tools that
are more native to these kind of problems than general purpose programming
language.

~~~
esfandia
Epistemic logic would probably be the appropriate tool; at least that's what I
thought when I first saw the problem. Epistemic logic is the logic of
knowledge and belief: you use a modal operator to express the knowledge of an
agent about a certain statement. The statement could be expressed in
propositional or first-order logic depending on the expressiveness required
(but of course there is a complexity trade-off).

Translating roughly from the problem statement (x being the variable holding
Cheryl's birthday):

Not(Know_Albert(x)) and Know_Albert(Not(Know_Bernard(x) etc.

Semantically, the possible birthdays correspond to the possible worlds. A
reasoner would be able to solve this by process of elimination, somewhat
similarly to a constraint-solver.

Resources:

Wikipedia entry on Epistemic Logic:
[http://en.wikipedia.org/wiki/Epistemic_modal_logic](http://en.wikipedia.org/wiki/Epistemic_modal_logic)

Fagin, Ronald; Halpern, Joseph; Moses, Yoram; Vardi, Moshe (2003). Reasoning
about Knowledge: [http://www.amazon.com/Reasoning-About-Knowledge-Ronald-
Fagin...](http://www.amazon.com/Reasoning-About-Knowledge-Ronald-
Fagin/dp/0262562006)

I haven't read the entire book, but the first couple of chapters give you an
idea and some great examples not too different from this puzzle.

------
frik
Could one use Julia instead of Python?

"iPython" already supports Haskell and Julia kernels too. A iPython Javascript
kernel would also make sense given its popularity and its functional inspired
syntax.

~~~
frik
A downvoter confused "iPython", its a "notebook" based (think Mathematica
notebook) command shell for interactive computing in multiple programming
languages. They already renamed it to "Jupyter" as "iPython" was very
confusing name.

------
andrewprock
Unfortunately, there are a number of rather curious, and culturally specific,
assumptions one must make about the problem.

The real puzzles are:

1\. "Why did Albert speak first?"

2\. "Why did he speak in such cryptic language?"

~~~
anigbrowl
These are actually valid questions and you shouldn't be downvoted. The
standard interpretation of the problem is highly questionable; Albert's
initial remark is not actually dispositive to Bernhard, because if Bernhard
had the 19 May date he would know the correct answer immediately without
needing Albert to say anything.

The suggestion that Albert's first statement necessarily eliminates all dates
in May is false, and the answer is indeterminable, as can be readily verified
with a Venn diagram. It took me some time to spot the flaw in the problem
construction; I initially found the official solution persuasive, but when you
think more carefully about it you realize it's actually wholly illogical.

~~~
Nursie
If we take silence as indicative of lack of knowledge, then nobody needs to
speak.

    
    
      Bernard: Silence (he doesn't know the answer)
      Albert: Silence (he doesn't either)
      Bernard: I know it!
    

Interestingly it then becomes relevant _who was silent first_.

Basically it's nonsense.

~~~
sukilot
If you assume Albert and Bernard are identical computers running identical
programs, then it isn't nonsense. And that's not just a gimmick , timing
analysis is how some side-channel attacks work in crypto.

~~~
Nursie
Of course it's nonsense.

If we can deduce the answer from silence then there's no need for any of the
information given in the question, it's not a logic puzzle it's bullshit.

I don't assume Albert and Bernard are anything, if you've made assumptions
beyond what's stated in the question then you've done it wrong.

And yes, I understand timing oracles.

