Created
December 4, 2017 14:23
-
-
Save ldd/b75ce7649f2d8cd389b2200911285338 to your computer and use it in GitHub Desktop.
Advent of code - Day 1
This file contains hidden or 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
defmodule ElixirPlayground.DayOne do | |
@input "./lib/elixir_playground/input/day1.txt" | |
defp parseInput do | |
@input | |
|> File.read! | |
|> String.trim | |
|> Kernel.to_charlist | |
end | |
def sumDuplicates do | |
parseInput() | |
|> (fn a -> a ++ Enum.take(a, 1) end).() | |
|> Enum.chunk_every(2,1,:discard) | |
|> Enum.filter(fn [a,b] -> a == b end) | |
|> Enum.map( fn [a,_] -> a end) | |
|> Enum.sum | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment