From ba73dab3643c604178c92292485011fa78f20aa2 Mon Sep 17 00:00:00 2001 From: Justin Wernick Date: Tue, 17 Sep 2024 11:12:36 +0200 Subject: Day 8 --- 2015/day8.exs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 2015/day8.exs (limited to '2015') 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}") -- cgit v1.2.3