The Towers of Hanoi as an Erlang program.
Erlang is a general-purpose programming language and runtime environment. Erlang has built-in support for concurrency, distribution and fault tolerance. Erlang is used in several large telecommunication systems from Ericsson. The most popular implementation of Erlang is available as open source from the open source erlang site.
Please refer to the Erlang web site for details.
%% The Towers Of Hanoi
%% Copyright (C) 2002 Amit Singh. All Rights Reserved.
%% Last tested under Erlang (BEAM) emulator version 126.96.36.199
m(F,T) -> io:format("~w~s~w~n", [F, " --> ", T]).
h(1,F,U,T) -> m(F, T);
h(N,F,U,T) when N > 0 ->
h(N - 1, F, T, U),
h(N - 1, U, F, T).
hanoi(0) -> io:format("number of disks cannot be 0~n");
hanoi(N) when N < 0 -> io:format("number of disks must be > 0~n");
hanoi(N) when N > 10 -> io:format("number of disks must be < 10~n");
hanoi(N) -> h(N, 1, 2, 3).