diff --git a/.gitignore b/.gitignore index 2196f88..5e6d62a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ main -target/ \ No newline at end of file +target/ +input.txt \ No newline at end of file diff --git a/2021/Day1/Elixir/main.ex b/2021/Day1/Elixir/main.ex new file mode 100644 index 0000000..b7fe34e --- /dev/null +++ b/2021/Day1/Elixir/main.ex @@ -0,0 +1,33 @@ +# iex()> Day1.load_file |> Day1.first + +defmodule Day1 do + def load_file() do + File.read!("input.txt") + |> String.split("\n", trim: true) + |> Enum.map(fn n -> Integer.parse(n) end) + |> Enum.map(fn tup -> Kernel.elem(tup, 0) end) + end + + @spec first([Integer]) :: Integer + def first(input) do + Enum.zip(0..length(input), input) + |> Enum.reduce(0, fn ({index, distance}, acc) -> + case index - 1 do + -1 -> + 0 + previousIndex -> + previous = Enum.at(input, previousIndex) + if distance > previous do + acc + 1 + else + acc + end + end + end) + end + + @spec second([Integer]) :: Integer + def second(input) do + :second + end +end