What's the problem with the prisoner to be hanged logic puzzle

A criminal is imprisoned on Monday, and told "you will have been hanged by the weekend, but you won't know which day we'll hang you."

If it gets to Thursday midnight and he's not been hanged yet, he knows they will hang him on Friday.

So they can't hang him on Friday, because they've told him he won't know when he'll be hanged.

That means he must be hanged before Friday, but if it gets to Wednesday midnight and he's not been hanged yet he knows he will be hanged on Thursday, but they can't do that because now he knows when he will be hanged. Etc.

I don't understand where the flaw in either the criminal's logical reasoning or in the guard's statement is, because I feel like the guards will turn up on any day and surprise the prisoner because he didn't "know" they'd be coming (he'd have ruled it off as impossible given what they told him at the start of the week).

Please can someone explain what's going on here.

• Why would "when" by synonymous to "on what day"? – Arnaud Mortier Mar 11 at 22:01
• @ArnaudMortier okay fine, fixed – theonlygusti Mar 11 at 22:02
• In the usual version it is said that the day of the hanging will bring a surprise to the prisoner. The prisoner then makes the above reasoning and thinks he can't be hanged at all. But because of this, when they come and hang him anyway, that's a surprise! – Arnaud Mortier Mar 11 at 22:09

This is a classic paradox and, to quote the Wikipedia article about it,

Despite significant academic interest, there is no consensus on its precise nature and consequently a final correct resolution has not yet been established.

So if you're expecting anyone here to provide something that once you see it is obviously The One True Explanation Of What's Going On, I fear you'll be disappointed. The description on the Wikipedia page isn't bad, though. To summarize the two approaches there:

• If you interpret "you won't know" as something like "you won't be able to prove rigorously using this statement as an axiom", then it turns out that what the prisoner's been told is logically inconsistent. There's no paradox, exactly; obviously anyone can say something logically inconsistent and then kill the prisoner; the only difficulty is with the fact that it seems to have turned out true, which a logically inconsistent thing shouldn't be able to; but note that in fact the prisoner was able to prove from the given axiom that he would be executed on whichever-day-it-actually-was, as well as that he would be executed the day before, etc., so in fact what it said was not true.
• The paradox depends on having the prisoner know that what the judge says is correct. He really isn't in a position to know that. (He's been told it, but that's not the same thing, especially as in the usual telling of the story he thinks about it and ends up explicitly not believing what he's been told.)
• what do you think of Amorydai's answer – theonlygusti Mar 12 at 8:03
• I don't find it entirely convincing. But this paradox is very confusing and hard to think clearly about, so it's entirely possible that the problem is in my thinking rather than Amorydai's. – Gareth McCaughan Mar 12 at 15:45

Well, even though this is a well known "paradox", I'll give you my two cents on it:

Putting aside the fact that the prisoner can 100% be expecting to hang at any moment, so it is impossible to "surprise" him. The prisoner is making a mistake in his second analysis about Wednesday night.
First, he correctly surmises that if he is still alive on Thursday night, then there is only one day left to hang him, so he will not be surprised to be hanged on Friday, and thus they can't hang him on Friday. However, what's hidden in this assumption is that he is alive on Thursday night. So the correct statement is:
"IF I wasn't hanged on Monday, Tuesday, Wednesday or Thursday, THEN I cannot be hanged on Friday.

However, for his second statement he reasons: if I'm alive on Wednesday night, then they have to hang me on Thursday, because I already deduced that they can't hang me on Friday, so I will not be surprised. BUT if he is alive on Wednesday night, he cannot for sure say that he will not be hanged on Friday, because for that statement to be true he has to not be hanged on Thursday, but it is not Thursday yet. Thus, he cannot predict that Thursday is the last day to hang him.

As a side note, one way out for the guards is to do the following: if, on Wednesday night, the prisoner is expecting to hang on Thursday, and "knows" that that is the day it's going to happen, then the guards can come to him on Thursday morning and ask "Will you be surprised to hang today?" He can tell them "No, I will not be surprised to hang today, I know this is the last day to do it." If the guards then wait until Friday to hang him, they would have pulled a fast one on him. Since he "knew" that they were going to do it Thursday, logically that means that he didn't "know" that they will do it Friday. So they're in the clear!

• Imagine it's Wednesday night. The guards "can't" hang him on Friday because by the time it gets to Friday he will know that that is the day he is to be hanged. But that means they will hang him on Thursday (the only other day left). However now he knows they will hang him on Thursday they're not allowed to. – theonlygusti Mar 12 at 5:10
• @theonlygusti That's the thing, he doesn't "know" they will hang him on Thursday. They might hang him on Thursday, or they might do it on Friday. So he doesn't know. The only reason he thinks they have to do it on Thursday, is because he thinks they can't do it on Friday, but the only way for them not to be able to do it on Friday, is if they didn't do it on Thursday. But since it's not Thursday yet, that means they can still do it on Friday, and he can't be certain that they won't until they do or don't on a Thursday. So he has no idea and will be surprised. – Amorydai Mar 12 at 5:50