From 3e21b24509ccccc07d8b04f5b25f31c14b599f12 Mon Sep 17 00:00:00 2001
From: Sloane Perrault <sloane.perrault@gmail.com>
Date: Wed, 21 Sep 2022 09:19:53 -0400
Subject: [PATCH] solve 2015 day 10

---
 2015/README.md      |  5 ++++-
 2015/lib/2015/10.ex | 33 +++++++++++++++++++++++++++++++++
 README.md           |  6 ++++++
 3 files changed, 43 insertions(+), 1 deletion(-)
 create mode 100644 2015/lib/2015/10.ex

diff --git a/2015/README.md b/2015/README.md
index 3341f6a..bcb8be2 100644
--- a/2015/README.md
+++ b/2015/README.md
@@ -15,7 +15,7 @@
 |  S  |  M  |  T  |  W  |  T  |  F  |  S  |
 | :-: | :-: | :-: | :-: | :-: | :-: | :-: |
 |     |     | [1] | [2] | [3] | [4] | [5] |
-| [6] | [7] |  8  |  9  |  10 | 11  | 12  |
+| [6] | [7] | [8] | [9] | [10]| 11  | 12  |
 | 13  | 14  | 15  | 16  | 17  | 18  | 19  |
 | 20  | 21  | 22  | 23  | 24  | 25  |     |
 
@@ -26,3 +26,6 @@
 [5]: ./lib/2015/5.ex
 [6]: ./lib/2015/6.ex
 [7]: ./lib/2015/7.ex
+[8]: ./lib/2015/8.ex
+[9]: ./lib/2015/9.ex
+[10]: ./lib/2015/10.ex
diff --git a/2015/lib/2015/10.ex b/2015/lib/2015/10.ex
new file mode 100644
index 0000000..cf80c57
--- /dev/null
+++ b/2015/lib/2015/10.ex
@@ -0,0 +1,33 @@
+import AOC
+
+aoc 2015, 10 do
+  def look_and_say(s) when is_binary(s),
+    do:
+      String.to_integer(s)
+      |> Integer.digits()
+      |> look_and_say()
+      |> IO.iodata_to_binary()
+
+  def look_and_say([x | xs]), do: look_and_say(xs, {x, 1})
+  def look_and_say([x | xs], {x, c}), do: look_and_say(xs, {x, c + 1})
+  def look_and_say([x | xs], state), do: [look_and_say([], state), look_and_say(xs, {x, 1})]
+  def look_and_say([], {x, c}), do: [Integer.to_string(c), Integer.to_string(x)]
+
+  def p1 do
+    Enum.reduce(1..40, String.trim(input_string()), fn iteration, acc ->
+      IO.puts("#{iteration / 40 * 100}%")
+
+      look_and_say(acc)
+    end)
+    |> String.length()
+  end
+
+  def p2 do
+    Enum.reduce(1..50, String.trim(input_string()), fn iteration, acc ->
+      IO.puts("#{iteration / 50 * 100}%")
+
+      look_and_say(acc)
+    end)
+    |> String.length()
+  end
+end
diff --git a/README.md b/README.md
index 6341bfb..0ebd672 100644
--- a/README.md
+++ b/README.md
@@ -6,8 +6,14 @@
 
 ## Years
 
+1. [2015]
+1. 2016
+1. 2017
+1. 2018
+1. 2019
 1. [2020]
 1. [2021]
 
+[2015]: ./2015
 [2020]: ./2020
 [2021]: ./2021