summaryrefslogtreecommitdiff
path: root/2015
diff options
context:
space:
mode:
Diffstat (limited to '2015')
-rw-r--r--2015/day25.exs25
1 files changed, 25 insertions, 0 deletions
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}")