Skip to content

Commit

Permalink
advent of code 2024 day 01 solution
Browse files Browse the repository at this point in the history
  • Loading branch information
wasi0013 committed Dec 1, 2024
1 parent bd70300 commit ae9d4de
Show file tree
Hide file tree
Showing 3 changed files with 1,041 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/y2024/day_01.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
defmodule Aoc.Y2024.Day01 do
@moduledoc """
Solved https://adventofcode.com/2024/day/1
"""
import Aoc.Helper.IO
import Aoc.Helper.Util

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)

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)
end

def get_input() do
get_string_input("2024", "01")
|> String.split("\n")
|> Enum.map(fn string -> string |> String.split(" ") |> Enum.map(&String.to_integer/1) end)
end

def solved_status(), do: :unsolved
end
Loading

0 comments on commit ae9d4de

Please sign in to comment.