-1
試圖模擬河內遊戲單元塔,但我無法正確打印列表。Erlang打印列表
-module(hanoi).
-export([create_towers/1]).
create_towers(0) ->
[];
create_towers(X) ->
List = [X | create_towers(X - 1)],
List1 = lists:sort(List),
io:format("Tower1: ~p ~n", [List1]).
當我運行函數:
67> hanoi:create_towers(3).
Tower1: [1]
** exception error: no function clause matching lists:sort([2|ok]) (lists.erl, line 479)
in function hanoi:create_towers/1 (hanoi.erl, line 9)
in call from hanoi:create_towers/1 (hanoi.erl, line 8)