Created
December 8, 2015 19:43
-
-
Save AntonFagerberg/5d73b3e58984842a7bf3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input = File.read!("/Users/anton/Desktop/input") |> String.split("\n") | |
a = input |> Enum.map(&String.length/1) |> Enum.sum | |
b = input |> Enum.map(fn a -> Regex.scan(~r/(\\x[a-f0-9]{2}|\\\"|\\\\|\")/, a) |> length end) |> Enum.map(&(&1 - 2)) |> Enum.sum | |
c = input |> Enum.map(fn a -> Regex.split(~r/(\\x[a-f0-9]{2}|\\\"|\\\\|\")/, a, trim: true) |> Enum.map(&String.length/1) |> Enum.sum end) |> Enum.sum | |
a - b - c | |
## Part 2 | |
input = File.read!("/Users/anton/Desktop/input") |> String.split("\n") | |
a = input |> Enum.map(&String.length/1) |> Enum.sum | |
b = input |> Enum.map(fn a -> Regex.scan(~r/(\"|\\)/, a) |> Enum.map(&length/1) |> Enum.sum end) |> Enum.map(&(&1 + 2)) |> Enum.sum | |
c = input |> Enum.map(fn a -> Regex.split(~r/(\"|\\)/, a, trim: true) |> Enum.map(&String.length/1) |> Enum.sum end) |> Enum.sum | |
b + c - a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment