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