diff options
author | Justin Wernick <j.wernick@eyeo.com> | 2024-09-17 11:12:36 +0200 |
---|---|---|
committer | Justin Wernick <j.wernick@eyeo.com> | 2024-09-17 11:12:36 +0200 |
commit | ba73dab3643c604178c92292485011fa78f20aa2 (patch) | |
tree | 1e59fabf7c1638d571843785a055737b91497832 /2015 | |
parent | d73fb26f45ab871515020bd470cf03fdc91a705e (diff) |
Day 8
Diffstat (limited to '2015')
-rw-r--r-- | 2015/day8.exs | 26 |
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}") |