title: Erlang Towers of Hanoi
body: <p>Currently stuck on trying to implement the towers of hanoi using a collection. I am trying to follow the example in Java using stacks <a href="http://www.sanfoundry.com/java-program-implement-solve-tower-of-hanoi-using-stacks/" rel="nofollow">http://www.sanfoundry.com/java-program-implement-solve-tower-of-hanoi-using-stacks/</a>, but I am getting </p>
  
  <pre><code>-module(toh).
  -export([begin/0]).
  begin() -&gt; 
    Pegs = 3,
    TowerA = createTowerA(N),
    TowerB = [],
    TowerC = [],
    move(Pegs, TowerA, TowerB, TowerC).
  
  %fills Tower A with integers from Pegs to 1.
  createTowerA(0) -&gt; [];
  createTowerA(N) when N &gt; 0 -&gt;
     [N] ++ createTowerA(N - 1).
  
  %displays the towers
  display(A, B, C) -&gt; 
     io:format("~w\t~w\t~w~n", [A, B, C]).
  
  move(Pegs, TowerA, TowerB, TowerC) -&gt; 
    if Pegs &gt; 0 -&gt;
      move(Pegs, TowerA, TowerC, TowerB),
      Temp = lists:last(TowerA),
      NewTowerC = C ++ Temp,
      NewTowerA = lists:sublist(TowerA, length(TowerA) - 1),
      display(NewTowerA, B, NewTowerC),
      move(Pegs - 1, B, NewTowerA, NewTowerC);
    end
  </code></pre>
  
  <p>When I try running the code, I get this error.</p>
  
  <pre><code>{"init terminating in do_boot",{undef,[{toh,begin,[],[]},{init,begin_i
  t,1,[{file,"init.erl"},{line,1057}]},{init,begin_em,1,[{file,"init.erl"},{line,1
  037}]}]}}
  
  Crash dump was written to: erl_crash.dump
  init terminating in do_boot ()
  </code></pre>
  
  <p>Can someone see why this is not working? I'm just trying to follow the sanfoundry example.</p>