[erlang-questions] help with smoker's problem
Wed Aug 13 04:34:43 CEST 2008
2008/8/13 Jared Langson <>:
> I decided to solve the smoker's problem to get a feel for the language.
> Anyways the arbiter (Sally) never reaches the end of her "loop". She stops
> "looping" after a seemingly random amount. Sometimes once, but I've never
> seen her go above 300 repititions. Any ideas as to what I am doing wrong?
I'm not familiar with this problem, but I see 2 potential issues with
your code :
1. In Sally's second "receive" clause, you are sending a message to
Mat but then receiving from Paul. Looks like you should be receiving
2. The more general problem is that is that you assume that if Tom,
Mat or Paul is giving Sally one of their items that they themselves
can never be the second smoker. So for example, what happens if Tom
is giving you tobacco when Tom is the second smoker? That case is
never catered for, AFAICS.
You probably want to look at ways to avoid all the repetition in
sally(). For example, if you knew what item was associated with the
FirstSmoker and SecondSmoker and also who the remaining smoker was you
could cut out a lot of similar code You could use something like a
dict() to store the running totals for each person.
More information about the erlang-questions