summaryrefslogtreecommitdiff
path: root/2015
diff options
context:
space:
mode:
authorJustin Wernick <justin@worthe-it.co.za>2024-10-24 10:54:13 +0200
committerJustin Wernick <justin@worthe-it.co.za>2024-10-24 10:54:13 +0200
commit839d10224aae540c38ab20e20c8aaddcd327113c (patch)
treefa177df390e7c49c911492e23c965774e4b15d13 /2015
parent893421f95f86c0ae61862b1014388a471693c5cf (diff)
Day 25HEADmain
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}")