summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Wernick <j.wernick@eyeo.com>2024-09-20 11:31:05 +0200
committerJustin Wernick <j.wernick@eyeo.com>2024-09-20 11:31:05 +0200
commitc8d9b2a1398786b1f0627e27c519fae35698b8a2 (patch)
treee8aa53db93f04bb9329feaae77f4cf1251ec8b16
parent4e0f286dfc3a8bf70752f138520bfd33fb2f3825 (diff)
Day 10
-rw-r--r--2015/day10.exs18
1 files changed, 18 insertions, 0 deletions
diff --git a/2015/day10.exs b/2015/day10.exs
new file mode 100644
index 0000000..384a15f
--- /dev/null
+++ b/2015/day10.exs
@@ -0,0 +1,18 @@
+start = File.read!("inputs/day10.txt")
+
+lookAndSayStream =
+ Stream.iterate(start, fn current ->
+ Regex.scan(~r/(\d)\1*/, current)
+ |> Enum.map(fn [seq, _] ->
+ length = String.length(seq)
+ type = String.at(seq, 0)
+ "#{length}#{type}"
+ end)
+ |> Enum.join()
+ end)
+
+[fourtiethEntry] = Stream.drop(lookAndSayStream, 40) |> Enum.take(1)
+IO.puts("Fourtieth Entry Length: #{String.length(fourtiethEntry)}")
+
+[fiftiethEntry] = Stream.drop(lookAndSayStream, 50) |> Enum.take(1)
+IO.puts("Fiftieth Entry Length: #{String.length(fiftiethEntry)}")