Browse Source

Day 10-2

trunk
Shanti Chellaram 3 years ago
parent
commit
a4ca8f4a20
  1. 20
      day10.erl

20
day10.erl

@ -3,7 +3,7 @@
-export([solve/1]). -export([solve/1]).
solve(Input) -> solve(Input) ->
{part1(Input), none}.
{part1(Input), io:format("~s~n", [part2(Input)])}.
part1(Input) -> part1(Input) ->
History = run(Input, [{1, 1}]), History = run(Input, [{1, 1}]),
@ -12,6 +12,24 @@ part1(Input) ->
Key * element(2, lists:keyfind(Key, 1, History)) Key * element(2, lists:keyfind(Key, 1, History))
end, end,
lists:sum(lists:map(Score, Interesting)). 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(<<"\n", Rest/binary>>, StateIn) ->
run(Rest, StateIn); run(Rest, StateIn);

Loading…
Cancel
Save