21 lines
412 B
Elixir
21 lines
412 B
Elixir
|
list = File.read!("input.txt")
|
||
|
|> String.split("\n")
|
||
|
|> Enum.map(&String.to_integer/1)
|
||
|
|
||
|
ans1 = list
|
||
|
|> Enum.sum()
|
||
|
IO.puts(ans1)
|
||
|
|
||
|
reducer = fn i, {current, seen} -> frequency = current + i
|
||
|
if MapSet.member?(seen, frequency) do
|
||
|
{:halt, frequency}
|
||
|
else
|
||
|
{:cont, {frequency, MapSet.put(seen, frequency)}}
|
||
|
end
|
||
|
end
|
||
|
|
||
|
ans2 = list
|
||
|
|> Stream.cycle()
|
||
|
|> Enum.reduce_while({0, MapSet.new([0])}, reducer)
|
||
|
IO.puts(ans2)
|