Formatters work. Still need to write random testers.
This commit is contained in:
parent
9ac442ffb4
commit
79eb881208
@ -228,7 +228,7 @@ jp(Unit, Precision, Pucks) when Pucks < 0 ->
|
||||
bestern2(gaju, Ranks, Span, 0, Pucks) ->
|
||||
G = lists:reverse(integer_to_list(Pucks div one_gaju())),
|
||||
case Span of
|
||||
3 -> period(" G", Ranks, G);
|
||||
3 -> period("G", Ranks, G);
|
||||
4 -> myriad(gaju_mark(), Ranks, G)
|
||||
end;
|
||||
bestern2(gaju, Ranks, Span, all, Pucks) ->
|
||||
@ -236,7 +236,7 @@ bestern2(gaju, Ranks, Span, all, Pucks) ->
|
||||
Zilch = lists:all(fun(C) -> C =:= $0 end, P),
|
||||
{H, T} =
|
||||
case {Span, Zilch} of
|
||||
{3, false} -> {bestern2(gaju, Ranks, 3, 0, Pucks), period(" P", Ranks, lists:reverse(P))};
|
||||
{3, false} -> {bestern2(gaju, Ranks, 3, 0, Pucks), period("P", Ranks, lists:reverse(P))};
|
||||
{4, false} -> {jp(gaju, 0, Pucks), myriad(puck_mark(), Ranks, lists:reverse(P))};
|
||||
{3, true} -> {bestern2(gaju, Ranks, 3, 0, Pucks), ""};
|
||||
{4, true} -> {jp(gaju, 0, Pucks), ""}
|
||||
@ -258,7 +258,7 @@ bestern2(gaju, Ranks, Span, Precision, Pucks) ->
|
||||
case lists:all(fun(C) -> C =:= $0 end, PuckingString) of
|
||||
false ->
|
||||
case Span of
|
||||
3 -> period(" P", Ranks, PuckingString);
|
||||
3 -> period("P", Ranks, PuckingString);
|
||||
4 -> myriad(puck_mark(), Ranks, PuckingString)
|
||||
end;
|
||||
true ->
|
||||
@ -273,7 +273,7 @@ bestern2(puck, Ranks, Span, all, Pucks) ->
|
||||
case lists:all(fun(C) -> C =:= $0 end, P) of
|
||||
false ->
|
||||
case Span of
|
||||
3 -> period(" P", Ranks, P);
|
||||
3 -> period("P", Ranks, P);
|
||||
4 -> myriad(puck_mark(), Ranks, P)
|
||||
end;
|
||||
true ->
|
||||
@ -297,7 +297,7 @@ bestern2(puck, Ranks, Span, Precision, Pucks) ->
|
||||
case lists:all(fun(C) -> C =:= $0 end, PuckingString) of
|
||||
false ->
|
||||
case Span of
|
||||
3 -> period(" P", Ranks, PuckingString);
|
||||
3 -> period("P", Ranks, PuckingString);
|
||||
4 -> myriad(puck_mark(), Ranks, PuckingString)
|
||||
end;
|
||||
true ->
|
||||
@ -312,15 +312,15 @@ bestern2(puck, Ranks, Span, Precision, Pucks) ->
|
||||
period(Symbol, Ranks, [$0, $0, $0 | PT]) ->
|
||||
rank3(Ranks, PT, [Symbol]);
|
||||
period(Symbol, Ranks, [P3, $0, $0 | PT]) ->
|
||||
rank3(Ranks, PT, [P3, Symbol]);
|
||||
rank3(Ranks, PT, [P3, 32, Symbol]);
|
||||
period(Symbol, Ranks, [P3, P2, $0 | PT]) ->
|
||||
rank3(Ranks, PT, [P2, P3, Symbol]);
|
||||
rank3(Ranks, PT, [P2, P3, 32, Symbol]);
|
||||
period(Symbol, Ranks, [P3, P2, P1 | PT]) ->
|
||||
rank3(Ranks, PT, [P1, P2, P3, Symbol]);
|
||||
rank3(Ranks, PT, [P1, P2, P3, 32, Symbol]);
|
||||
period(Symbol, _, [P3]) ->
|
||||
[P3, Symbol];
|
||||
[P3, 32, Symbol];
|
||||
period(Symbol, _, [P3, P2]) ->
|
||||
[P2, P3, Symbol].
|
||||
[P2, P3, 32, Symbol].
|
||||
|
||||
rank3([_ | RT], [$0, $0, $0 | PT], A) ->
|
||||
rank3(RT, PT, A);
|
||||
@ -455,10 +455,10 @@ read([C | Rest])
|
||||
C =:= $\n ->
|
||||
read(Rest);
|
||||
read([C | Rest]) when $0 =< C andalso C =< $9 ->
|
||||
read(Rest, [C], {[], []});
|
||||
read(Rest, [C], []);
|
||||
read([C | Rest]) when $0 =< C andalso C =< $9 ->
|
||||
NumC = C - $0 + $0,
|
||||
read(Rest, [NumC], {[], []});
|
||||
read(Rest, [NumC], []);
|
||||
read(_) ->
|
||||
error.
|
||||
|
||||
@ -483,15 +483,11 @@ read_w_gajus([], A) ->
|
||||
G = list_to_integer(lists:reverse(A)) * one_gaju(),
|
||||
{ok, G};
|
||||
read_w_gajus([C, 32 | Rest], A) ->
|
||||
read(Rest, [], {[{C, A}], []});
|
||||
read_w_gajus([32, $G | Rest], A) ->
|
||||
case read(Rest, [], {[{$G, A}], []}) of
|
||||
{ok, P} ->
|
||||
G = list_to_integer(lists:reverse(A)) * one_gaju(),
|
||||
{ok, G + P};
|
||||
Error ->
|
||||
Error
|
||||
end;
|
||||
read(Rest, [], [{C, A}]);
|
||||
read_w_gajus([32, $G, 32 | Rest], A) ->
|
||||
read(Rest, [], [{$G, A}], []);
|
||||
read_w_gajus([32, $G], A) ->
|
||||
calc([{$G, A}], []);
|
||||
read_w_gajus(_, _) ->
|
||||
error.
|
||||
|
||||
@ -509,43 +505,53 @@ read_w_pucks([], A) ->
|
||||
{ok, list_to_integer(Padded)}.
|
||||
|
||||
|
||||
read([C | Rest], A, S) when $0 =< C andalso C =< $9 ->
|
||||
read(Rest, [C | A], S);
|
||||
read([C | Rest], A, S) when $0 =< C andalso C =< $9 ->
|
||||
read([C | Rest], A, G) when $0 =< C andalso C =< $9 ->
|
||||
read(Rest, [C | A], G);
|
||||
read([C | Rest], A, G) when $0 =< C andalso C =< $9 ->
|
||||
NumC = C - $0 + $0,
|
||||
read(Rest, [NumC | A], S);
|
||||
read([$木], A, {G, P}) ->
|
||||
calc({[{$木, A} | G], P});
|
||||
read([$木, 32 | Rest], A, {G, P}) ->
|
||||
read(Rest, [], {[{$木, A} | G], P});
|
||||
read([$本], A, {G, []}) ->
|
||||
calc({[], [{$本, A} | G]});
|
||||
read([$本], A, {G, P}) ->
|
||||
calc({G, [{$本, A} | P]});
|
||||
read([32, $G], A, {G, P}) ->
|
||||
calc({[{$G, A} | G], P});
|
||||
read([32, $G, 32 | Rest], A, {G, P}) ->
|
||||
read(Rest, [], {[{$G, A} | G], P});
|
||||
read([32, $P], A, {G, []}) ->
|
||||
calc({[], [{$P, A} | G]});
|
||||
read([32, $P], A, {G, P}) ->
|
||||
calc({G, [{$P, A} | P]});
|
||||
read([C, 32 | Rest], A, {G, []}) ->
|
||||
read(Rest, [], {[{C, A} | G], []});
|
||||
read([C, 32 | Rest], A, {G, P}) ->
|
||||
read(Rest, [], {G, [{C, A} | P]});
|
||||
read([C | Rest], A, {G, []}) ->
|
||||
read(Rest, [], {[{C, A} | G], []});
|
||||
read([C | Rest], A, {G, P}) ->
|
||||
read(Rest, [], {G, [{C, A} | P]});
|
||||
read(_, _, _) ->
|
||||
read(Rest, [NumC | A], G);
|
||||
read([$木], A, G) ->
|
||||
calc([{$G, A} | G], []);
|
||||
read([$G], A, G) ->
|
||||
calc([{$G, A} | G], []);
|
||||
read([$木, 32 | Rest], A, G) ->
|
||||
read(Rest, [], [{$G, A} | G], []);
|
||||
read([$G, 32 | Rest], A, G) ->
|
||||
read(Rest, [], [{$G, A} | G], []);
|
||||
read([$本], A, P) ->
|
||||
calc([], [{$P, A} | P]);
|
||||
read([$P], A, P) ->
|
||||
calc([], [{$P, A} | P]);
|
||||
read([C, 32 | Rest], A, G) ->
|
||||
read(Rest, [], [{C, A} | G]);
|
||||
read([C | Rest], A, G) ->
|
||||
read(Rest, [], [{C, A} | G]);
|
||||
read(Rest, A, G) ->
|
||||
io:format("read(\"~ts\", ~tp, ~tp) -> died!~n", [Rest, A, G]),
|
||||
error.
|
||||
|
||||
calc({G, P}) ->
|
||||
io:format("G: ~tp, P: ~tp~n", [G, P]),
|
||||
case calc(G, 0) of
|
||||
|
||||
read([C | Rest], A, G, P) when $0 =< C andalso C =< $9 ->
|
||||
read(Rest, [C | A], G, P);
|
||||
read([C | Rest], A, G, P) when $0 =< C andalso C =< $9 ->
|
||||
NumC = C - $0 + $0,
|
||||
read(Rest, [NumC | A], G, P);
|
||||
read([$本], A, G, P) ->
|
||||
calc(G, [{$P, A} | P]);
|
||||
read([$P], A, G, P) ->
|
||||
calc(G, [{$P, A} | P]);
|
||||
read([C, 32 | Rest], A, G, P) ->
|
||||
read(Rest, [], G, [{C, A} | P]);
|
||||
read([C | Rest], A, G, P) ->
|
||||
read(Rest, [], G, [{C, A} | P]);
|
||||
read(_, _, _, _) ->
|
||||
io:format("read/4 died!~n"),
|
||||
error.
|
||||
|
||||
calc(G, P) ->
|
||||
case calc(gaju, G, 0) of
|
||||
{ok, Gajus} ->
|
||||
case calc(P, 0) of
|
||||
case calc(puck, P, 0) of
|
||||
{ok, Pucks} -> Gajus + Pucks;
|
||||
error -> error
|
||||
end;
|
||||
@ -553,47 +559,43 @@ calc({G, P}) ->
|
||||
error
|
||||
end.
|
||||
|
||||
calc([{_, []} | S], A) ->
|
||||
calc(S, A);
|
||||
calc([{M, Cs} | S], A) ->
|
||||
calc(U, [{_, []} | S], A) ->
|
||||
calc(U, S, A);
|
||||
calc(U, [{M, Cs} | S], A) ->
|
||||
case magnitude(M) of
|
||||
{ok, J} ->
|
||||
N = list_to_integer(lists:reverse(Cs)) * J,
|
||||
calc(S, A + N);
|
||||
N = list_to_integer(lists:reverse(Cs)) * J * unit(U),
|
||||
calc(U, S, A + N);
|
||||
Error ->
|
||||
Error
|
||||
end;
|
||||
calc([], A) ->
|
||||
calc(_, [], A) ->
|
||||
{ok, A}.
|
||||
|
||||
unit(gaju) -> one_gaju();
|
||||
unit(puck) -> 1.
|
||||
|
||||
|
||||
magnitude($木) ->
|
||||
{ok, one_gaju()};
|
||||
magnitude($本) ->
|
||||
{ok, 1};
|
||||
magnitude($G) ->
|
||||
{ok, one_gaju()};
|
||||
{ok, 1};
|
||||
magnitude($P) ->
|
||||
{ok, 1};
|
||||
magnitude(Mark) ->
|
||||
io:format("Mark: ~ts~n", [[Mark]]),
|
||||
case rank(Mark, ranks(jp), 1_0000, 1) of
|
||||
{ok, J} ->
|
||||
{ok, J};
|
||||
error ->
|
||||
case rank(Mark, ranks(metric), 1_000, 1) of
|
||||
case rank([Mark, 32], ranks(metric), 1_000, 1) of
|
||||
{ok, J} -> {ok, J};
|
||||
error -> rank(Mark, ranks(heresy), 1_000, 1)
|
||||
error -> rank([Mark, 32], ranks(heresy), 1_000, 1)
|
||||
end
|
||||
end.
|
||||
|
||||
|
||||
rank(Mark, [Mark | _], Magnitude, Sum) ->
|
||||
{ok, Sum * Magnitude};
|
||||
rank(Mark, [_ | Rest], Magnitude, Sum) ->
|
||||
rank(Mark, Rest, Magnitude, Sum * Magnitude);
|
||||
rank(_, [], _, _) ->
|
||||
io:format("failure to rank!~n"),
|
||||
error.
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user