
The Firing Squad Problem - jgrahamc
http://www-cs-faculty.stanford.edu/~eroberts/courses/soco/projects/2004-05/automata-theory/problem.html
======
acadien
Feynman discusses this problem in his "Theory of Computation" book. If I
remember correctly, its actually part of a joke he plays on the reader too. In
one of the earlier chapters he brings up the problem and then assigns it to
the reader as homework they should complete before moving on. I spent maybe a
week or two on that problem, discussed it with coworkers... and we came up
with nothing.

So I gave up and continued reading. Then somewhere in the 4th or 5th Chapter
he says something like: Oh I hope you had fun with the Firing Squad Problem, I
still work on it from time to time and hope to come up with a solution myself
one day.

Facepalm.

Edit: Here is a link to the book, its enjoyable for experts and laymen alike.
[http://www.amazon.com/Feynman-Lectures-On-Computation-
Richar...](http://www.amazon.com/Feynman-Lectures-On-Computation-
Richard/dp/0738202967/ref=sr_1_1?ie=UTF8&qid=1391792191&sr=8-1&keywords=theory+of+computation+feynman)

~~~
Casseres
When you keep presenting a supposedly unsolvable problem to people who don't
know it, then you might get lucky. George Dantzig was one such person. He
arrived late to class, saw some problems on the board, assumed they were
homework, and solved them. He wasn't constrained by the common thought that
these were "unsolvable".

~~~
georgecmu
They were not "unsolvable", they were simply not solved yet (at the time
Dantzig saw them on the blackboard).

[http://www.snopes.com/college/homework/unsolvable.asp](http://www.snopes.com/college/homework/unsolvable.asp)

~~~
benaiah
Did you read the comment? He said they were considered unsolvable at the time,
not that they were unsolvable. Of course they're solvable - they were solved.

~~~
georgecmu
That is precisely my point. They were not considered "unsolvable" (i.e.
impossible to solve), they were considered "unsolved" (i.e. not solved yet)
and were presented as such. Do you really need me to explain distinctions in
meaning here?

------
judk
This is one of those problems where the illustration is severely misleading
from the intended theoretical problem. The problem assumes that all nodes
share a synchronized time step, but do not have a clock, and only communicate
by trading notes, which is an incredibly awkward assumption. The problem works
better without the title and metaphor.

For example, a much better metaphor would be schoolchildren passing notes
among neighbors every time the teacher turns their back, coordinating a
simultaneous outburst.

~~~
jgrahamc
In Hillis' book the clock is provided by a military drummer beating time on a
drum.

~~~
thaumasiotes
That's an unfortunate metaphor; it completely spoils the problem. Just have
the _drummer_ give the signal to fire, and all the soldiers will hear him
simultaneously.

------
tzs
A few years ago, a friend asked me if I had any interesting problems he and a
coworker of his could work on for fun. One of the problems I gave him was this
(although I presented it as a state machine problem, not a firing square
problem).

In a burst of over-enthusiasm, I also quickly hacked together a simple state
machine simulator that he and his coworker could use to test their proposed
solution(s).

The problem specification, state machine simulator, and documentation are
available here: [https://github.com/tzs/problems-state-machine-
sync](https://github.com/tzs/problems-state-machine-sync)

I told them I would consider it solved if they could describe the algorithm.
They did not need to actually specify fully working state machines that dealt
with all the details.

Much to my surprise, especially considering that my friend had not studied
computer science beyond what was given in a high school programming class, not
only did they solve the problem in a few days, they produced fully working
state machines.

Another puzzle I gave them consisted of several images that show the tracks of
a bicycle. One of the wheels is leaving a red track and one a blue track
(color assignment was random for each image). Their task: determine in each
image whether the bike was traveling left to right or right to left. Here are
the images: [http://imgur.com/a/hv0b0](http://imgur.com/a/hv0b0)

It was also randomly determined for each image whether to draw the front wheel
track first or rear wheel track first, so you cannot deduce anything from
which track appears to be on top when they cross.

~~~
sys_argv
Ok. I'm stumped. Could you give me a hint

~~~
tzs
If you want a hint for the firing squad, start out by limiting the number of
participants to powers of two, and think recursively.

If you want a hint for the bicycle problem, think about tangents.

~~~
chmike
Anyone who drives a bycicle knows that the rear wheel follows a smooth path
compared to the front wheel. So this image is easy. I guess there might be
more tricky images. A straight line for instance ;)

------
javajosh
This is an interesting theory problem, but it might be clearer to talk about
shooters at a firing range, separated by partitions such that they can each
only talk to their neighbors. The barriers eliminates the trivial solution of
the shout: "Fire on the count of 3!" that common sense would provide.

The simplest solution would be to establish a clock, because with a clock you
can say "Fire at 1pm exactly!". But even this is interesting because it
requires shooters to know where they are in the line in order to take into
account any signal propogation delay. If each person takes 1s to repeat a
message that they hear, then it takes n seconds to go down the line, and each
shooter must know how to compensate for that delay. E.g. the first shooter
hears "it's noon", the next shooter hears "it's noon" but knows that he's 1s
away from the source, and can calculate that the time is actually 12:01, the
next shooter knows it's 12:02 etc. They could synchronize clocks, specify a
time "shoot at 1pm!" and get the job done.

But what if we take away their clocks? This is where my intuition fails me,
because I don't see how the problem can be solved without clocks. If you don't
have clocks, you need to somehow get a signal to every shooter simultaneously,
which I think is theoretically impossible, since without a clock the shooter
cannot execute instructions on their own.

Which probably means I don't fully understand the scenario :)

~~~
dkokelley
I think the purpose is to solve the scenario where each node has a perfect
internal clock, but no external reference clock. A rough solution is to
initiate a count from the origin, starting from 0. Each node hears the
previous neighbor's count, increments it by 1 and sounds off. When the end
node is reached, it knows how far the signal propagated. At this point a
reverse count is initiated, terminating in 0 at the origin. Each node along
the way back hears the adjacent node begin its countdown, and starts its own
countdown from its relative position. The return signal reaches the origin
node just as the remainder of the nodes reach 0, and all node execute
simultaneously on 0 (with appropriate modification for any fencepost
problems).

No external reference clock is required, and assuming each node counts at
exactly the same rate, all nodes act in unison.

~~~
xenophanes
the problem is with no clocks, and is possible.

you also can't count the soldiers because you don't have unlimited memory
(states), so you might run out of memory (states) to count in.

------
sramsay
> At every count, each soldier looks at their neighbors, considers what they
> themselves were already doing, and decides what to do next, completely
> according to what they see.

Anyone else think this is an incredibly ugly problem statement? It's like they
thought firing squads were cool and tried to shoehorn the problem into it any
way they could.

~~~
xenophanes
Feynman gave the firing squad problem in his lectures on computation, so it
can't be a modern shoehorn.

------
ChuckMcM
Its interesting to see people get stuck on the "Firing Squad" aspect of it.
There is an insight there about communicating through metaphor effectively.

As a synchronization problem this one was a lot of fun, I too encountered it
in the Feynman book and later used variants of it in interviewing folks for
Google. Basically once you get into the realm of distribution the ability to
get large groups of programs working together introduces a lot of complexity
into an otherwise straightforward problem space.

An interesting variant is that you create a line of students. The teacher asks
them to form a line at the door with the tallest student in front and the
shortest in the back. How can any given student know its there turn to join
the line at the door?

------
granfalloon
I'm assuming that when it says a "fixed number of states," it means that the
number of states can't be tied to the number of soldiers in the line? (e.g., a
five state solution would have to work for any number of soliders)

~~~
granfalloon
Realized my question may have come across as rhetorical, but I really am
looking for clarification on the rules!

~~~
algorias
Yes you have a constant number of states at your disposal. Otherwise, there is
a trivial solution that takes _n_ or so time, matching the theoretical lower
bound (imposed by the "speed of light" for information propagation in this
kind of automaton), rendering the problem thoroughly uninteresting.

------
snake_plissken
I came here hoping to encounter a rousing debate on why we should use the
firing squad for all executions, but this is much more interesting.

~~~
saraid216
That does say something about how political HN has become.

------
eru
This is a nice one to solve for yourself. The two-dimensional (and higher)
problems are still research material.

~~~
tzs
I assume that it is research material if you are trying to find the solution
with the minimal number of states or the fastest sync time or something like
that?

The two (or higher) dimensional problem if you aren't requiring some kind of
optimal or minimal solution is a trivial extension of the one dimensional
problem. E.g., for two dimensions, you essentially do the one dimensional
solution along the top row to sync up all the elements there, and then they
simultaneously start the one dimensional solution on the columns.

~~~
eru
Yes, I was talking about solutions with special properties, like eg being
optimal or minimal in some sense.

------
grogenaut
Turn on a light above the target's head. Shoot on target. Demote general for
wasting everyone time.

~~~
oh_sigh
Then the person who is the closest to the light will know that he is the one
who killed the individual.

~~~
CamperBob2
No, the way firing squads work is that a randomly-chosen member fires a blank.
No one can know for certain if they delivered a lethal round.

~~~
biot
While you may not know if your rifle _has_ a blank, you'll definitely know if
your rifle _fired_ a blank due to the different force in recoil because you're
accelerating the mass of gunpowder+lead vs gunpowder alone.

~~~
CamperBob2
Not sure how true that is. How much recoil force is contributed by the bullet
versus the gas that propels it?

------
e12e
It would a appear a visual cue by the target would be superior... propagates
to all soldiers at the speed of light, assuming normal rifles (range etc), all
soldiers are likely to receive the signal at what for practical purposes are
the same time -- the signal might be created by way of a mirror reflecting on
the wall, so doesn't require any special technology, and can be projected
almost instantaneously ... sadly such a practical solution makes for very a
trivial fsm...

~~~
pfarrell
For n large enough, this visual based solution would not suffice. Light based
communication is the fastest on the universe but not instantaneous.

Imagine there exists a line of soldiers, 96 million miles long,...

-Or-

Imagine there exist n datacenters which need to coordinate an action with
nanosecond accuracy and are connected by fiber optic cable...

~~~
hamburglar
I think one of the interesting aspects of the problem is that it illustrates
just how much more complicated a mechanism needs to be if you aren't allowed
to introduce some basic functionality like clock synchronization.

We know the automata have clocks, so if they're actually allowed to count
cycles to keep a concept of synchronized time, then the problem becomes very
simple: a counter is started at 0 and sent from one end of the line to the
other. When it reaches the other end of the line, the last node knows how long
before the signal can get back to the beginning of the line and sends 2 __n
back across as the time everyone will fire. Super simple solution in 2 __n
time.

That's not to say it's a stupid problem -- it's both fun and useful to
consider what exactly you'd need to do if you had to solve a problem with the
given constraints, because it helps you understand the cost of those
constraints and whether all the extra algorithm complexity is worth it. Not to
mention that if you're just going to punk out and say you'll use synchronized
clocks, then you've got a whole new set of issues. :)

------
judk
It is a bit distracting to place a theoretical problem in an unnecessarily
morbid context. We don't have to be dark to be cool. How about a "cheerleader
coordination problem" or the "Sing Happy Birthday problem"?

~~~
philwelch
That's a decent concern troll. I give you 6 out of 10.

~~~
Crito
Definitely at least an 8/10\. Look at all the replies.

~~~
philwelch
HN is too easy a target.

