functional programming - Erlang Towers of Hanoi -
Currently trying to implement Hanoi towers using a collection. I'm trying to use the pile in Java in the example but I'm getting
-module (toh). Export ([Start / 0]). Start () - & gt; Pegs = 3, Tower A = Builder A (N), Tower B = [], Towerci = [], Move (Pegs, Tower A, Tower B, Towerier). Fill the tower A with the integer 1 with the pegs. Banatea (0) - & gt; []; CreateTowerA (N) when N & gt; 0 - & gt; [N] ++ BuildoverA (N-1). % Display the tower display (A, B, C) - & gt; Io: Format ("~ w \ t ~ w \ t ~ w ~ n", [A, B, C]). Move (Pegs, Tower A, Tower B, Towerier) - & gt; If the pegs & gt; 0 - & gt; (Tower A, Tower A, Tower B), Temp = Lists: Last (TowerA), NewTervacy = C ++ Temporary, NewTV = Lists: Sublink (Tower A, Length (TowerA) - 1), Display (Newtwire, B, Newt Sea, Move (Pegs - 1, B, Newtown, Newt Sea);
When I try to run the code, I get this error.
{"ends in do_boot", {undef, [{toh, begin, [INIT], [[file, "init.erl"}, {line, 1057}] }, {Init, start_em, 1, [{file, "init.erl"}, {Line, 1 037}]}}} Crash dump was written: erl_crash.dump ending init do_boot ()
Can anyone see why this is not working? I'm just trying to follow the code example.
This code can not be compiled, at least in variables / 4 It seems that you have not compiled this file before executing it.
Although Ergon has used a virtual machine, it must be compiled before execution.
The variable in this code: If you call again / 4 in the first line without using any returned value, then there can be no effect. Also if you are using the statement with a bad syntax. The correct syntax is:
if GuardSeq1 -> Body1; ...; Guards SEC - & gt; BodyN% is not a semicolon at the end of the last body.
If you want to use it, be careful that you should always have at least one guard that is true, otherwise the code Will crash.
My version [edit: delete useless function, print better]:
- Module (tow) export ([start / 1]). Start (n) - & gt; Game = # {1 = & gt; Lists: Seek (1, n), 2 = & gt; [], 3 = & gt; []}, Display (game, n), move (n, game, 1,3, n). Move (1, game, to, copy, size) - & gt; [H | Newform] = Maps: get (from, game), NETUTO = [H | Maps: Get (games, games)], NugmeM = maps: updates (from, newform, maps: updates (per, newto, games)), display (new game, size), nugam; Step (n, game, to, copy, size) - & gt; Other = other (from, from), Game1 = move (N-1, Game, From, Other, Size), Game2 = Move (1, Game1, From, Per, Size), Move (N-1, Game 2, Other, Shaping). Performance (# {1: = A, 2: = B, 3: = C}, D) - & gt; Listings: Exotic currency (fun (x) - & gt; print (x, d) end, list: zip 3 (full (a, d), full (b, d), full (c, d)), io : Format "~ n ~ r ~ n ~ n", [lists: copy (6 * d + 5, $ -)]). Complete (L, D) - & gt; List: Duplicate (D-Length (L), 0) ++ L Print ({A, B, C}, D) - & gt; Io: Format ("~ S ~ S ~ S ~ N", [AMM (A, D), AMM (B, D), AMM (C, D)]). AMM (I, D) - & gt; Lists: Duplicate (D-I, $) ++ Lists: Duplicate (I, $ _) ++ "|" ++ Lists: Duplicate (I, $ _) ++ Lists: Duplicate (D-I, $). Other (I, J) - & gt; 6-me-j.
In Shell:
Ashley v 6.1 (closing with g) 1> C (then). {OK, Toe} 2 & gt; So: the beginning (3). _ | _ | | __ | __ | | ___ | ___ | | ----------------------- | | | __ | __ | | ___ | ___ | _ | _ ----------------------- | | | | | | ___ | ___ __ | ___ | _ ----------------------- | | | | _ | _ | ___ | ___ __ | __ | ----------------------- | | | | _ | _ | | __ | __ ___ | ___ ----------------------- | | | | | | _ | ____ __ ___ | ___ ------------------------ | | | | | __ | ___ | _ | ___ | ___ ----------------------- | | _ | _ | | __ | __ | | ___ | ___ ----------------------- # {1 = & gt; [], 2 = & gt; [], 3 = & gt; [1,2,3]} 3>
Comments
Post a Comment