|
|
|
@ -3,7 +3,7 @@ |
|
|
|
-export([solve/1]). |
|
|
|
|
|
|
|
solve(Input) -> |
|
|
|
{part1(Input), none}. |
|
|
|
{part1(Input), io:format("~s~n", [part2(Input)])}. |
|
|
|
|
|
|
|
part1(Input) -> |
|
|
|
History = run(Input, [{1, 1}]), |
|
|
|
@ -12,6 +12,24 @@ part1(Input) -> |
|
|
|
Key * element(2, lists:keyfind(Key, 1, History)) |
|
|
|
end, |
|
|
|
lists:sum(lists:map(Score, Interesting)). |
|
|
|
part2(Input) -> |
|
|
|
History = run(Input, [{1, 1}]), |
|
|
|
render(History, []). |
|
|
|
|
|
|
|
render([{Cycle, X}|Rest], Acc) -> |
|
|
|
Prefix = |
|
|
|
case Cycle rem 40 == 0 of |
|
|
|
true -> "\n"; |
|
|
|
false -> [] |
|
|
|
end, |
|
|
|
Symbol = |
|
|
|
if |
|
|
|
X + 2 < Cycle rem 40 -> $.; |
|
|
|
X > Cycle rem 40 -> $.; |
|
|
|
true -> $# |
|
|
|
end, |
|
|
|
render(Rest, [Symbol|Prefix] ++ Acc); |
|
|
|
render([], Acc) -> Acc. |
|
|
|
|
|
|
|
run(<<"\n", Rest/binary>>, StateIn) -> |
|
|
|
run(Rest, StateIn); |
|
|
|
|