From 839d10224aae540c38ab20e20c8aaddcd327113c Mon Sep 17 00:00:00 2001 From: Justin Wernick Date: Thu, 24 Oct 2024 10:54:13 +0200 Subject: Day 25 --- 2015/day25.exs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 2015/day25.exs (limited to '2015') diff --git a/2015/day25.exs b/2015/day25.exs new file mode 100644 index 0000000..1aaaa5c --- /dev/null +++ b/2015/day25.exs @@ -0,0 +1,25 @@ +fileContents = File.read!("inputs/day25.txt") + +[row, column] = + Regex.run(~r/Enter the code at row (\d+), column (\d+)./, fileContents, capture: :all_but_first) + |> Enum.map(fn num -> + {num, ""} = Integer.parse(num) + num + end) + +codes = Stream.iterate(20_151_125, &rem(&1 * 252_533, 33_554_393)) + +indices = + Stream.iterate({1, 1}, fn + {1, col} -> {col + 1, 1} + {row, col} -> {row - 1, col + 1} + end) + +{{^row, ^column}, code} = + Stream.zip(indices, codes) + |> Enum.find(fn + {{^row, ^column}, _} -> true + _ -> false + end) + +IO.puts("Code: #{code}") -- cgit v1.2.3