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}")