Comment detail

LL Golf Hole 7 - バイト数を読みやすくする (Nested Flatten)
実行する場合は以下のようにコマンドを実行します。
数値はコマンドの引数として与えます。

erlc ファイル名
erl -noshell -s kuraidori put 数値 -s init stop

実行例
$ erl -noshell -s kuraidori put 1234567890 -s init stop
1.2G
$ erl -noshell -s kuraidori put 12345678901234 -s init stop
12.3T
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
-module(kuraidori).
-export([put/1]).

put([S]) -> loop(list_to_integer(atom_to_list(S))," KMGTPEZY").

loop(S,[H|[]]) -> pr(S,H);
loop(S,[H|_]) when S < 1000 ->
        if
        is_integer(S) -> pri(S,H);
        true -> pr(S,H)
        end;
loop(S,[_|L]) -> loop(S / 1000, L).

pr(S,K) -> io:format("~.1f~s~n",[S,[K]]).
pri(S,K) -> io:format("~.10B~s~n",[S,[K]]).

Index

Feed

Other

Link

Pathtraq

loading...