kgbu #7419(2008/08/27 09:41 GMT) [ Erlang ] Rating0/0=0.00
実行するには、以下のようにコマンド入力します。 コマンドの引数として数値を与えています。 一応、0のケースも入れておきました。 erlc スクリプトファイル名 erl -noshell -s pyramid main 自然数 -s init stop 実行例 $ erl -noshell -s pyramid main 0 -s init stop $ erl -noshell -s pyramid main 1 -s init stop * $ erl -noshell -s pyramid main 3 -s init stop * ** *** ** *
1 2 3 4 5 6 7 8 9 10 11
-module(pyramid). -export([main/1]). main([N])-> push(list_to_integer(atom_to_list(N)),[]). push(0,_)->0; push(1,L)->io:format("~s~n",[L ++ "*"]), pop(L ++ "*"); push(N,L)->io:format("~s~n",[L ++ "*"]), push(N - 1, L ++ "*"). pop("*")-> 0; pop([_|L])-> io:format("~s~n",[L]), pop(L).
Rating0/0=0.00-0+
1 reply [ reply ]
kgbu #7419() [ Erlang ] Rating0/0=0.00
-module(pyramid). -export([main/1]). main([N])-> push(list_to_integer(atom_to_list(N)),[]). push(0,_)->0; push(1,L)->io:format("~s~n",[L ++ "*"]), pop(L ++ "*"); push(N,L)->io:format("~s~n",[L ++ "*"]), push(N - 1, L ++ "*"). pop("*")-> 0; pop([_|L])-> io:format("~s~n",[L]), pop(L).Rating0/0=0.00-0+
1 reply [ reply ]