[erlang-questions] help with smoker's problem

Matthias Lang matthias@REDACTED
Mon Aug 18 11:48:03 CEST 2008

On Tuesday, August 12, Jared Langson wrote:
> I decided to solve the smoker's
> problem<http://en.wikipedia.org/wiki/Cigarette_smokers_problem>to get
> a feel for the language. 

Others have already commented on how to fix your solution.

I hadn't seen the smokers' problem (or, perhaps, forgotten it), so I
solved it for fun. It felt pretty pointless---what does "you're not
allowed to modify the agent code" mean when you're writing it all from
scratch? I chose to interpret it as "the smokers aren't allowed to
send each other messages". What does the second constraint mean in
Erlang? The solution in wikipedia removes so much of the problem that
it becomes almost unrecognisable, e.g. there's nothing called 'paper',
'match' or 'tobacco' in it! Convincing yourself it's correct is hard.

Anyway, are there more enjoyable problems for playing with Erlang? Two
spring to mind, but they're more suitable once you're reasonably 
comfortable with the language. They take about a day each.

The first is the POTS exercise. This is part of the Erlang course
taught at Ericsson (and probably also at Erlang Consulting & Training)
If you're lucky, you get an office phone system to play with and you
implement its control logic in Erlang.  You need to make sure the
right phone rings when you dial numbers, you need to take care of
conditions like trying to call a phone that's off-hook, and so
on. There's also a gs-based simulator, but as far as I know neither
the problem spec nor the simulator is available online. Oh well.

The second is to implement a lift controller. This problem is fairly
well known in the formal methods & SE world, e.g.


you can make it more complicated by having multiple lifts, inventing
scheduling strategies and by adding realism, for instance modelling
the subtleties of lifts that are in motion near stops---e.g.  a lift
needs, say, 2 metres of advance warning to stop somewhere. Like the
POTS exercise, a graphical simulator makes it more fun. Even with
multiple lifts, it's not as "concurrent" as it first seems.


More information about the erlang-questions mailing list