summaryrefslogtreecommitdiff
path: root/2015/day8.exs
diff options
context:
space:
mode:
Diffstat (limited to '2015/day8.exs')
-rw-r--r--2015/day8.exs26
1 files changed, 26 insertions, 0 deletions
diff --git a/2015/day8.exs b/2015/day8.exs
new file mode 100644
index 0000000..ecf9e79
--- /dev/null
+++ b/2015/day8.exs
@@ -0,0 +1,26 @@
+escapedList = File.stream!("inputs/day8.txt")
+
+savings =
+ Enum.map(escapedList, fn rawString ->
+ savedFromEscapes =
+ Regex.scan(~r/(\\\\|\\"|\\x[0-9a-f]{2})/, rawString, capture: :first)
+ |> Enum.map(fn [escape] -> String.length(escape) - 1 end)
+ |> Enum.sum()
+
+ 2 + savedFromEscapes
+ end)
+ |> Enum.sum()
+
+IO.puts("Potential savings: #{savings}")
+
+bloat =
+ Enum.map(escapedList, fn rawString ->
+ bloatFromNewEscapes =
+ Regex.scan(~r/(\\|\")/, rawString, capture: :first)
+ |> Enum.count()
+
+ 2 + bloatFromNewEscapes
+ end)
+ |> Enum.sum()
+
+IO.puts("Potential bloat: #{bloat}")