summaryrefslogtreecommitdiff
path: root/2015/day8.exs
blob: ecf9e797367dfb4b0b3fa104c4c7363aae8e0b1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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}")