1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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}")
|