For example, can a version of the code be used to solve the 'hardest puzzle' -
https://xkcd.com/blue_eyes.html
(solution: https://xkcd.com/solution.html) ?
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
If you properly understand those rules and convert them to code (as in the OP) then searching the possible answers for a match is trivial.
def statement3(date):
possible_dates = tell(Month(date))
return (not know(possible_dates)
and not know(filter(lambda x : not know(x),
[tell(Day(d)) for d in possible_dates])))The Python solution proposed is really great, in that it captures both the expressive and functional spirit of the language.
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...
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.
The trick is in figuring out what additional information is actually being added by whatever subsequent statements are being made.
It's weird. I usually have a lot of trouble with mathematical word puzzles. Particularly probability. But logic puzzles almost always seem to be pretty easy for me.
Now if you want a really fucking hard one, try your hand at this: http://en.wikipedia.org/wiki/The_Hardest_Logic_Puzzle_Ever
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.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.]
Heck, it's not even clear that Albert and Bernard are communicating with one another and not merely with the answerer. If you assume they do not communicate at all then the puzzle becomes impossible.
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...
I don't really think it's especially obfuscated though. You just have to think about why people are saying what they say, which is a fairly useful thing to be able to do...
http://jdh.hamkins.org/transfinite-epistemic-logic-puzzle-ch...
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.
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.
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.
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
Fagin, Ronald; Halpern, Joseph; Moses, Yoram; Vardi, Moshe (2003). Reasoning about Knowledge: http://www.amazon.com/Reasoning-About-Knowledge-Ronald-Fagin...
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.
"iPython" already supports Haskell and Julia kernels too. A iPython Javascript kernel would also make sense given its popularity and its functional inspired syntax.
The real puzzles are:
1. "Why did Albert speak first?"
2. "Why did he speak in such cryptic language?"
He says, "At first I didn't know", so all he could have said if he had spoken first would have been "I don't know when the birthday is". Then Albert would have said, "I don't know when the birthday is, and I knew that Bernard couldn't have".
So the problem is unchanged regardless of who speaks first.
It also doesn't seem that cryptic to me... It doesn't take that much reading between the lines to understand the statement "at first I didn't know, but I know now" to mean "the information that Albert just provided gives me enough information to determine the birthday"...
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.
Albert knows the month, and his statement, which translates directly to "given the month I know, it is not possible for Albert to independently determine the date" certainly does rule out the two months.
The whole ruckus surrounding this problem seems to be more a reflection of the sad state of the intelligence in our population, rather than anything to do with Asia.
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.