Day 1: Chronal Calibration - Advent of Code 2018
I did the Advent of Code 2018 day 1 challenge in Elixir! Parts one and two are as follows:
defmodule Day1 do
def frequency(input) do
input
|> read_input()
|> Enum.reduce(0, fn line, acc ->
String.to_integer(line) + acc
end)
end
def repeated_frequency(input) do
input
|> read_input()
|> Stream.cycle()
|> Enum.reduce_while({0, MapSet.new([0])}, fn line, {acc, seen} ->
value = String.to_integer(line) + acc
if MapSet.member?(seen, value) do
{:halt, value}
else
{:cont, {value, MapSet.put(seen, value)}}
end
end)
end
defp read_input(input) do
input
|> File.read!()
|> String.split("\n", trim: true)
end
end
:aoc2018 |> :code.priv_dir() |> Path.join("day1.txt") |> Day1.frequency()
:aoc2018 |> :code.priv_dir() |> Path.join("day1.txt") |> Day1.repeated_frequency()
![Simon Escobar Benitez](/uploads/media/speakers/0001/01/thumb_722_speakers_small.png)
ARTICLES: 8
Day 11: Chronal Charge - Advent of Code 2018
![Day 11: Chronal Charge - Advent of Code 2018](/uploads/media/articles/0001/01/63e322b220891c7f81b7a2468c6914ceb39a7f3f.png)
I did the Advent of Code 2018 day 11 challenge in Elixir! Parts one and two are as follows:
READ MOREDay 10: The Stars Align - Advent of Code 2018
![Day 10: The Stars Align - Advent of Code 2018](/uploads/media/articles/0001/01/450f1697974651b50d74fce5f03b2bed0fead382.png)
I did the Advent of Code 2018 day 10 challenge in Elixir! Parts one and two are as follows:
READ MOREDay 7: The Sum of Its Parts - Advent of Code 2018
![Day 7: The Sum of Its Parts - Advent of Code 2018](/uploads/media/articles/0001/01/a2f632e45209197c43636b4da1887ab38e2d8f76.png)
I did the Advent of Code 2018 day 7 challenge in Elixir! Parts one and two are as follows:
READ MOREDay 6: Chronal Coordinates - Advent of Code 2018
![Day 6: Chronal Coordinates - Advent of Code 2018](/uploads/media/articles/0001/01/978c395f39a6ce30d9db84a9b71c068f2f24ca62.png)
I did the Advent of Code 2018 day 6 challenge in Elixir! Parts one and two are as follows:
READ MOREDay 5: Alchemical Reduction - Advent of Code 2018
![Day 5: Alchemical Reduction - Advent of Code 2018](/uploads/media/articles/0001/01/4609e59fb2d556c4657bd52aea2a991dcd59a1f1.png)
I did the Advent of Code 2018 day 5 challenge in Elixir! Parts one and two are as follows:
READ MOREDay 4: Repose Record - Advent of Code 2018
![Day 4: Repose Record - Advent of Code 2018](/uploads/media/articles/0001/01/3996c8b8f765c5d1a0485e3bc309863d97427109.png)
I did the Advent of Code 2018 day 4 challenge in Elixir! Parts one and two are as follows:
READ MOREDay 3: No matter how you slice it - Advent of Code 2018
![Day 3: No matter how you slice it - Advent of Code 2018](/uploads/media/articles/0001/01/c4cdaaaaa6fbfc6d3be78ddcbe2f05bf8ccea64f.png)
I did the Advent of Code 2018 day 3 challenge in Elixir! Parts one and two are as follows:
READ MOREDay 2: Inventory Management System - Advent of Code 2018
![Day 2: Inventory Management System - Advent of Code 2018](/uploads/media/articles/0001/01/10a67edefbec721abd6940f0b4990adfc8683a1d.png)
I did the Advent of Code 2018 day 2 challenge in Elixir! Parts one and two are as follows:
READ MORE