24

I have heard of the puzzle with 100 or 10 dwarves wearing a hat of a color, either red or blue, and standing in a straight line, and having to guess the color of their own hat - it's quite easy.

The solution to save all dwarves or all dwarves minus the first one is fairly simple and relies on the fact that the number of dwarves is finite. So what would happen if you had an infinite number of dwarves standing in a straight line?

Every dwarf wears a hat of color either red or blue and sees the color of the hats of all the dwarves standing in front of him. There is explicitly a first dwarf, who has to start guessing the color of his hat and then the guessing proceeds with the next one in the line.

If a dwarf guessed correctly, it is freed; if he guessed wrong, it is fried. Every dwarf can hear the voice of all other dwarves without a problem. Everybody is only allowed to speak out either the color red or blue, but no further information.

Is there a possibility for all dwarves to be freed? Well, probably no.

But is it at least possible that only finitely many of them are killed?

EDIT: This is a mathematical puzzle. No loopholes.

Mike Earnest
  • 32,336
  • 6
  • 92
  • 237
Imago
  • 648
  • 7
  • 13
  • 3
    I think you should specify that the dwafs are facing the "infinite" direction. More specifically, that the dwarfs can be labeled by natural numbers, where each dwarf sees the dwarfs greater than it. – xnor Jan 12 '15 at 09:07
  • Are they allowed to discuss any kind of strategy before they go into this situation? – EFrog Jan 12 '15 at 09:16
  • 1
    Is this what you are searching for? – dmg Jan 12 '15 at 09:17
  • @dmg I don't understand that at all. There is an infinite number of possible sequences of hats a dwarf can see in front of him, so making a label for each sequence would be impossible. Especially if the only labels you can offer are "red" and "blue". I.e, just because the guy behind me says blue can't possibly determine whether my hat is red or blue, no matter what I see in front of me. Is there a way I can see examples of this in action? – EFrog Jan 12 '15 at 09:27
  • @EFrog have a look at my answer. It can be hard to wrap your head around it, but so are infinite dwarves. – dmg Jan 12 '15 at 10:16
  • 1
    I'm a little lost. What happens if every dwarf is wearing the same color hat? Or the colors are in a ratio of 7:3? Do there need to be an even number of blue and red hats? – SocioMatt Jan 12 '15 at 14:43
  • Can I just check whether the other dwarfs, or at least the one in front of a dwarf, can tell whether the latest nominee is freed or fried? – Joffan Jan 12 '15 at 19:37
  • 1
    Would you please pick a consistent terminology for directions? First you say "in front of", then you say "first" and then "next in line". It's all unnecessarily confusing to someone who doesn't already know what you're talking about. Also the first sentence is quite a muddle to someone who is not already familiar with the problem, and you quickly lead into a spoiler for it as well (well, it might be a spoiler, as soon as someone figures out what you mean by the first problem). How about trying to restructure the whole thing in a clear non-spoiler way? – Don Hatch May 30 '19 at 11:06

5 Answers5

9

This puzzle has been discussed on the Mathematics Stack Exchange as in this question: Prisoners Problem.

The solution given there (by Asaf Karagila):

Encode the colors into $0$ and $1$, and define the equivalence relation on $2^\Bbb N$, $\langle x_i\rangle\sim\langle y_i\rangle$ if and only if there is some $k$ such that for all $n\geq k$, $x_n=y_n$. Using the axiom of choice the prisoners pick a representative from each equivalence class.

In his turn, the $n$-th prisoner looks for the representative class fitting the string of hats he sees ahead, assuming that all hats up to him are blue. Since all the prisoners follow the same representative to guess their own color, it is guaranteed that after finitely many deaths, the representative and the fashionable selection of hats by the warden will agree, and everyone else will survive.

Note that since the Axiom of Choice is non-constructive, so is this solution and hence may not be practically useful for the dwarves in the question. There seems to be a fair bit of discussion on whether the Axiom of Choice is required. Well it was shown by Hardin and Taylor [Hardin, Christopher S.; Taylor, Alan D. An introduction to infinite hat problems. Math. Intelligencer 30 (2008), no. 4, 20–25] that there being no winning strategy is consistent with ZF (plus other axioms which don't imply the Axiom of Choice). So in that sense the Axiom of Choice is necessary for a winning strategy.

theosza
  • 1,275
  • 10
  • 12
7

The solution is the following:

We define the notion of a class of infinite sequence of hats. All sequences in this class differ from each other by only a finite number of elements. There are an infinite number of classes, each containing a infinite number of elements.

Why? As differences between classes are of infinite length, there is an infinite number of possible distances, which means there is an infinite number of classes.

For each such class we select a "representative" which is a single element of the class (a single infinite sequence of hats). So suppose we have the class "infinitely alternating red and blue, with a finite number of non-alternating hats in the first 20 elements". We can set the representative to be:

EDIT: Apparently, after digging a bit, a good way to define the classes is:

Two sequences are equivalent if they are identical after a finite number of items

Choice of a representative can be easily defined as choosing the sequence where the differences appear at the beginning of the sequence and are lexicographically smaller.

For example, the sequence

rbrbrbrbrbrb...

And, the sequence:

r[r]rb[br]rbrbrb... ([] denotes mismatches)

is a member of that class. Each dwarf can see the infinite sequence of hats in front of it and can recognize the class. The dwarves can see the mismatches in front of them, but do not know if their own hat is not a mismatch.

But, the difference is finite, and a modification of the standard rules for guessing a finite sequence can be applied. The first dwarf says "red" if there is an odd number of hats that are different in the "sequence", compared to the "representative" (or "blue" if the mismatches are even). From there on, each dwarf has sufficient info to tell the colour of their hat.

Note that, the number of classes is infinite, however, since we are talking about infinite dwarves, I assume this is acceptable.

Finally, since the first dwarf "guesses", the first dwarf has a 50% chance of survival, all other dwarves survive.

Oh, and because of the infinite number of classes, this can be directly applied to the problem with an infinite number of colours.

Summary for the naysayers

  • Two sequences are equivalent if they are identical after a finite number of items.

  • Choice of a representative can be easily defined as choosing the sequence where the differences appear at the beginning of the sequence and are lexicographically smaller.

  • As the sequence is infinite, and differences are finite, there exists an infinite subsequence, that can uniquely define the class of the sequence.

dmg
  • 5,294
  • 23
  • 35
  • There is discussion at: http://chat.stackexchange.com/rooms/20187/discussion-on-answer-by-dmg-infinite-dwarfs-wearing-infinite-hats-of-2-colours – Steve Jessop Jan 12 '15 at 16:25
  • 1
    Whoops, sorry, I tried to move the comments to chat, purged all the comments, and then realized I couldn't undelete my comment with the chatroom link on mobile. My bad; thanks for finding it. – Doorknob Jan 12 '15 at 16:31
  • 9
    I think you should mention that the axiom of choice is being used to pick the representative elements. You can't choose the lexicographically smallest element of the class, as there may be no minimum like for rrrrrr... . There is no constructive algorithm to find representatives. – xnor Jan 12 '15 at 19:07
  • How do we choose the class? It is because each dwarf is preceded by a finite number of dwarfs, and therefore can always see the class after him? – njzk2 Jan 12 '15 at 19:38
  • @njzk2 Yes, exactly. – xnor Jan 12 '15 at 19:57
  • @xnor : but then, for a dwarf to recognize the class, he must only look at hats that every dwarfs can see, doesn't he? – njzk2 Jan 12 '15 at 20:08
  • @njzk2 That's right. It's not a finite algorithm, if that's your concern. It's a function of infinitely many bits. – xnor Jan 12 '15 at 20:12
  • While this is an interesting theory, is it even possible to recognize the class? The number of classes is uncountably infinite, the same as the real numbers. I find it hard to believe that this could work unless the sequence is repeating (i.e. rational, and thus, countable). – Trenin Jan 13 '15 at 13:08
  • @Trenin What do you mean? We can recognize PI, can't we? – dmg Jan 13 '15 at 13:14
  • @dmg If you saw the binary expansion of sqrt(PI-e), would you be able to recognize it? – Trenin Jan 13 '15 at 13:20
  • @dmg You can probably recognize a finite number of classes, and I will concede that the dwarves can recognize a countably infinite number of classes, but there are uncountably infinity number of classes, and I don't see how they could do that. – Trenin Jan 13 '15 at 13:21
  • @Trenin And I don't see how there are infinite dwarves, and infinite hats and so on... Arguing over whether imaginary dwarves can memorize uncountably infinite classes is quite ridiculous. – dmg Jan 13 '15 at 13:27
  • @Trenin: The question is clearly physically impossible. Even if it were possible for infinitely many dwarfs to exist (which it is not), it's not possible for light from an infinite row of dwarfs to reach the first dwarf in finite time, so he can't ever "see all the hats" as stated. The only meaningful way to respond to the problem is to say something interesting about (physically impossible) operations on infinite data, and about what infinite data it is you're operating on, and what operations you're doing. Drawing a line and saying, "too infinite for me" just rules out some of the interest. – Steve Jessop Jan 13 '15 at 13:29
  • @SteveJessop I'm guessing that infinite dwarves, might get squashed into a black hole or something? Possibly devour the universe? Or stop time? Guess that is a solution as well :) – dmg Jan 13 '15 at 13:33
  • @dmg: asphyxiate when the straight line of dwarfs extends beyond the atmosphere ;-) What it means for the universe itself to be infinite can go on physics.stackexchange. No doubt an ultra-finitist mathematician would respond to the question by saying, "sorry, how many dwarfs did you say there are? You made a noise, but that noise wasn't a number". That is to say, they'd be like Trenin but more so, they'd refuse to accept any hypotheticals about infinite objects/operations even if they're countable. – Steve Jessop Jan 13 '15 at 13:34
  • 5
    Anyway, this answer is a bit like solving a puzzle "I have one ball and a knife. I need two balls. How do I get them?" by appealing to the Banach-Tarski dissection. Perfectly reasonable as long as the puzzle is about surprising consequences of the axiom of choice, not about actual balls cut up with actual knives. The answer makes a point, but the point is not about what dwarfs in hats can do, it's about uncountable infinities. – Steve Jessop Jan 13 '15 at 13:53
  • @dmg You started this by saying you can recognize PI. My point is there are an uncountable number of sequences here and it is not as simple as recognizing a few irrational number sequences. The majority of the real numbers are transcendental, which means that you can't even express them with algebraic numbers in an equation. – Trenin Jan 13 '15 at 14:24
  • A solution should show how the class is recognized. To wave your hands and say it is unimportant how this is done because there is no point in arguing about infinities is a bit of a cop out. – Trenin Jan 13 '15 at 14:30
  • All I would like to know is what theoretical algorithm or method do the dwarves use to recognize the class? I am not arguing about the physical impossibility of the question, only the theoretical solution to the theoretical question. – Trenin Jan 13 '15 at 14:35
  • I don't understand what "Choice of a representative can be easily defined as choosing the sequence where the differences appear at the beginning of the sequence and are lexicographically smaller." means. The differences to what? Lexicographically smaller than what? – JiK Jan 14 '15 at 14:27
  • The representative is not well defined in your solution. The "difference" is not a property of a single sequence, but a pair of sequences. For any given sequence we can choose another one for which the different part end at an arbitrarily large position, so there's no string for which the difference appear "at the beginning" only. And the class doesn't have the smallest element lexically (except for (0) class), as for any given element you can construct a smaller sequence by changing first 1 to 0. The rest of solution is great, but we need a solid representative choice algorithm. – Hubert OG Apr 14 '16 at 17:53
  • @SteveJessop I laughed out loud when I read "Using the axiom of choice the prisoners pick a representative from each equivalence class." in the other answer. Now I'm imagining a meeting of the Dwarven bureaucracy where they're officially picking representatives from each equivalence class "using the axiom of choice". Maybe in a Greg Egan short story that would work. – Stef Dec 19 '23 at 23:27
2

A solution that saves all the dwarves except (maybe) the first one. It is very similar to the one given by theosza, but it also mixes an idea used in the original problem with finitely many dwarves.

We partition $\{ 0,1 \}^{\mathbb{N}}$ with the equivalence $ (x_j)_{j \in \mathbb{N}} \sim (y_j)_{j \in \mathbb{N}}$ if and only if there exists $k \in \mathbb{N}$ such that forall $ n \geq k $ we have that $x_n=y_n$. Now with the axiom of choice, the dwarves choose a representative $\tilde{x} =(\tilde{x}_j)_{j \in \mathbb{N}}$ from each equivalence class. Now the first dwarf sees in front of him a sequence of $ (x_j)_{j \geq 1} $ and he knows the class of equivalence and hence the representative $\tilde{x}$, so he can determine a $k \in \mathbb{N}$ such that for all $n \geq k$ we have $x_n = \tilde{x}_n$. Now the representative and the real sequence of hats may differ only on finitely many hats, the first $k$ hats, the first dwarf sees $k-1$ hats and says "blue" if $x_n \neq \tilde{x}_n $ for an odd number of indices $1 \leq n \leq k-1$ and says "red" if $x_n \neq \tilde{x}_n $ for an even number of indices $1 \leq n \leq k-1 $. The second dwarf sees $(x_j)_{j \geq 2}$, he knows $\tilde{x}$ and he knows also if the representative and the sequences of hats differ from an even number or an odd number of hats (because he hears what the first dwarf said), so he can deduce the color of his hat, i.e. he can deduce if either $x_1 = \tilde{x}_1$ or $x_1 \neq \tilde{x}_1$. The third one knows $\tilde{x}$, he sees $(x_j)_{j \geq 3} $, he knows also $x_1$ and he can deduce $x_2$ thanks to the first dwarf. Inductively we continue in this way, the $n$-th dwarf sees $(x_j)_{j \geq n}$, he knows the representative $\tilde{x}$, he knows $(x_j)_{1 \leq j \leq n-2}$, and thanks to the first dwarf he can deduce his hat, i.e. if $x_{n-1}$ is equal to $\tilde{x}_{n-1}$ or differs from $\tilde{x}_{n-1}$. So all the dwarves, except maybe the first one, guess correctly because they all follow the same representative $\tilde{x} $.

3m0o
  • 317
  • 1
  • 8
2

Refer to the following link. The one answer which is simple to understand is the High pitch and low pitch. Each dwarfs answers his hat color in either high pitch or low pitch depending on the next dwarfs hat whether its in Red or Blue color.

  • Well that's certainly got the merit of simplicity! – A E Jan 12 '15 at 13:42
  • 1
    The linked question is explicitly about the finite case; and your answer, while clever, isn't really satisfying: the intent is clearly that each dwarf can communicate only one bit to the neighbor in front of him. – Daniel Wagner Jan 12 '15 at 14:30
  • 3
    They could impart several bits, if required: high/low, loud/quiet, fast/slow - and remember that humans (and presumably dwarves) are not binary - we can at the very least differentiate three (high/normal/low, fast/normal/slow, loud/normal/quiet) levels for each of these measurements. I make that a minimum of 27 bits even assuming that three levels per measurement is as as fine grained as we can get, that there is only one word and there are no other ways to inflect the word. – Jon Story Jan 12 '15 at 17:11
  • No, this is wrong. The dwarves can only call out a hat color, they can't do it in different pitches. – Gilles 'SO- stop being evil' Jan 12 '15 at 17:14
  • 8
    Says who? I don't see that in the rules – Jon Story Jan 12 '15 at 17:15
  • I had rewritten the rules, check the edit. Now the riddle should be clear. – Imago Jan 12 '15 at 19:02
-1

I was wondering if a dwarf with infinite range of sight can identify repeating pattern(s)?

What if there is only one single pattern that is infinite? This would mean the dwarfs can't be saved :(

Due to the fact that the number of dwarfs is infinite, there must be a repeating pattern at some point (this is almost too complicated for me now!). With infinite sight, every dwarf can find his own position within the repeating pattern (which can be very, very, very long).

Having said that, a dwarf can never be sure whether he really identified a pattern correctly since the number of dwarfs is infinite and he would have to see all dwarfs at once in order to be sure - which is impossible due to "infinite number",... I think?

Avigrail
  • 3,020
  • 1
  • 30
  • 66
  • 1
    There can be an infinite sequence which does not have a repeating pattern. For example rbrrbbrrrbbb... – dmg Jan 13 '15 at 07:53
  • @dmg (read the 'deleted' line). You are right, but it is infinite and 'infinite' includes the guarantee of a repeating pattern somewhere. I think this is a matter of definition? – Avigrail Jan 13 '15 at 08:12
  • 1
    PI is an example of a non-repeating infinite pattern. – dmg Jan 13 '15 at 08:29
  • But you never know because you can never see ALL decimals (infinite, you know) - maybe there is some pattern in the infinite distance... it is a conflict between definition and brain and I think we will never agree because we simply can't! – Avigrail Jan 13 '15 at 08:38
  • 3
    The brain doesn't really handle infinity well :) Just look at Cantor – dmg Jan 13 '15 at 08:40
  • @bobbee What do you mean by "pattern"? Do you mean a sequence of hat colors that repeats forever, starting from some point? If so, it can be shown that almost no sequences have a pattern. – Lopsy Jan 13 '15 at 11:40
  • I think of pattern as a sequence of hat colors that repeats forever, yes. Therefore I don't think this will work :( – Avigrail Jan 13 '15 at 12:49
  • OK: Better example than PI: what about 0,1 01 001 0001 00001 000001 ... ? Is there a pattern, that repeats itself ? – Imago Jan 13 '15 at 13:07
  • As I said, you never know unless you oversee an infinite number and we can never find an answer to it. – Avigrail Jan 13 '15 at 13:11
  • @bobbee: well, if you can never know, you certainly can't rely on there being one as in your answer. Mathematicians have various techniques for defining this sort of thing, but with respect, trying to deal with it without seeing or re-inventing those techniques is a bit like a monkey trying to play chess. Even in the unlikely event that it moves the pieces according to the rules, it won't play well because it doesn't understand the goal. There are much better puzzles for the purpose of introducing infinity, for example see "Hilbert's Hotel". – Steve Jessop Jan 13 '15 at 13:43
  • There is an endless-monkey theory :) – Avigrail Jan 13 '15 at 13:43
  • 1
    @bobbee: ah, yes, watching the best monkey out of an infinite number of monkeys play chess is awesome. I was referring to watching one monkey play chess ;-) – Steve Jessop Jan 13 '15 at 13:45
  • All of the irrational numbers named in comments so far have patterns, simply because it's impossible to indicate precisely a number that doesn't. I recommend considering the case where every single dwarf's hat color is chosen randomly, rather than following the bits of a number chosen in advance. The bits will still correspond to an irrational number, but it will be a properly patternless one. – Brilliand Jan 13 '15 at 19:56
  • @Brilliand Sure, every number indicated so far has a pattern in that sense. However, he is speaking a pattern specifically as "a sequence of hat colors that repeats forever". In this sense, any irrational number is a counter-example. – KSmarts Feb 02 '15 at 19:42