diff --git a/2024/day22.exs b/2024/day22.exs index 47969ce..ca0c2da 100755 --- a/2024/day22.exs +++ b/2024/day22.exs @@ -22,11 +22,10 @@ defmodule Day22 do def part2(input) do input |> Enum.map(fn secret -> - secret - |> Stream.iterate(&next/1) - |> Stream.map(&bananas/1) - |> Stream.take(2000) - |> Stream.chunk_every(5, 1, :discard) + 1..2000 + |> Enum.map_reduce(secret, fn _, secret -> {rem(secret, 10), next(secret)} end) + |> elem(0) + |> Enum.chunk_every(5, 1, :discard) |> Enum.reduce(%{}, fn [a, b, c, d, bananas], changes -> Map.put_new(changes, {b - a, c - b, d - c, bananas - d}, bananas) end) @@ -36,10 +35,6 @@ defmodule Day22 do |> elem(1) end - def bananas(secret) do - secret |> Integer.to_string() |> String.last() |> String.to_integer() - end - def input do with [input_filename] <- System.argv(), {:ok, input} <- File.read(input_filename) do