diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..d8df771 --- /dev/null +++ b/.tool-versions @@ -0,0 +1,2 @@ +elixir 1.17.3-otp-27 +erlang 27.1.2 diff --git a/README.md b/README.md index f3f2c48..863bc93 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,8 @@ Run all tests: 2024 1 + :green_circle: :green_circle: - :white_circle: :white_circle: diff --git a/lib/y2024/day_01.ex b/lib/y2024/day_01.ex index 4fdabf3..e1678f2 100644 --- a/lib/y2024/day_01.ex +++ b/lib/y2024/day_01.ex @@ -1,4 +1,4 @@ -defmodule Aoc.Y2024.Day01 do +defmodule Aoc.Y2024.Day01 do @moduledoc """ Solved https://adventofcode.com/2024/day/1 """ @@ -8,14 +8,17 @@ defmodule Aoc.Y2024.Day01 do def solve_part1(data) do data |> rotate90() - |> then (fn [list1, list2] -> [Enum.sort(list1), Enum.sort(list2)] |> Enum.zip() |> Enum.map(&Tuple.to_list/1) |> Enum.map(fn [a, b] -> abs(a - b) end) |> Enum.sum() end) - + |> Enum.map(&Enum.sort/1) + |> Enum.zip() + |> Enum.map(&Tuple.to_list/1) + |> Enum.map(fn [a, b] -> abs(a - b) end) + |> Enum.sum() end def solve_part2(data) do data |> rotate90() - |> then (fn [list1, list2] -> Enum.map(list1, fn a -> a * Enum.count(list2, &(a==&1)) end) |> Enum.sum() end) + |> then(fn [list1, list2] -> Enum.map(list1, fn a -> a * Enum.count(list2, &(a == &1)) end) |> Enum.sum() end) end def get_input() do diff --git a/test/y2024/day_01_test.exs b/test/y2024/day_01_test.exs index 1b34769..8e1e54c 100644 --- a/test/y2024/day_01_test.exs +++ b/test/y2024/day_01_test.exs @@ -4,7 +4,7 @@ defmodule AocTest.Y2024.Day01Test do import Aoc.Y2024.Day01 test "Part 1 is solved" do - assert solve_part1(get_input()) == 1388114 + assert solve_part1(get_input()) == 1_388_114 end test "Part 2 is solved" do