diff --git a/2025/day01.livemd b/2025/day01.livemd index a890637..f2ced72 100644 --- a/2025/day01.livemd +++ b/2025/day01.livemd @@ -28,6 +28,8 @@ instructions = end) ``` + + ## Part 1 ```elixir @@ -39,6 +41,8 @@ end) |> elem(1) ``` + + ## Part 2 ```elixir @@ -62,4 +66,4 @@ end) |> elem(1) ``` - + diff --git a/2025/day02.livemd b/2025/day02.livemd index e52d040..1aa1d79 100644 --- a/2025/day02.livemd +++ b/2025/day02.livemd @@ -24,6 +24,7 @@ ranges = |> Enum.map(&String.to_integer/1) |> then(&apply(Range, :new, &1)) end) +|> Enum.sort_by(& &1.last) ``` ## Implementation @@ -59,6 +60,8 @@ defmodule ElfRanges do end ``` + + ## Part 1 ```elixir @@ -68,6 +71,8 @@ ranges |> Enum.sum() ``` + + ## Part 2 ```elixir @@ -77,4 +82,4 @@ ranges |> Enum.sum() ``` - + diff --git a/2025/day03.livemd b/2025/day03.livemd index 0f5247c..bd040a7 100644 --- a/2025/day03.livemd +++ b/2025/day03.livemd @@ -4,7 +4,7 @@ Mix.install([:kino_aoc]) ``` -## Section +## Parse @@ -37,16 +37,20 @@ defmodule Joltage do end ``` + + ## Part 1 ```elixir Enum.sum_by(batteries, &Integer.undigits(Joltage.make_largest(&1, 2))) ``` + + ## Part 2 ```elixir Enum.sum_by(batteries, &Integer.undigits(Joltage.make_largest(&1, 12))) ``` - + diff --git a/2025/day04.livemd b/2025/day04.livemd index 530901a..3683c3f 100644 --- a/2025/day04.livemd +++ b/2025/day04.livemd @@ -4,7 +4,7 @@ Mix.install([:kino_aoc]) ``` -## Setup +## Parse @@ -32,14 +32,14 @@ rolls = ```elixir defmodule PaperRolls do - def adjacent({x, y}) do + defp adjacent({x, y}) do for dx <- -1..1, dy <- -1..1, {dx, dy} != {0, 0}, do: {x + dx, y + dy} end - def free?(pos, map) do + def movable?(pos, map) do pos |> adjacent() |> Enum.count(&(&1 in map)) @@ -48,12 +48,16 @@ defmodule PaperRolls do end ``` + + ## Part 1 ```elixir -Enum.count(rolls, &PaperRolls.free?(&1, rolls)) +Enum.count(rolls, &PaperRolls.movable?(&1, rolls)) ``` + + ## Part 2 ```elixir @@ -61,7 +65,7 @@ cleaned = Stream.repeatedly(fn -> [] end) |> Enum.reduce_while(rolls, fn _, acc -> removable = - Enum.filter(acc, &PaperRolls.free?(&1, acc)) + Enum.filter(acc, &PaperRolls.movable?(&1, acc)) |> MapSet.new() case MapSet.difference(acc, removable) do @@ -75,4 +79,4 @@ cleaned = MapSet.size(rolls) - MapSet.size(cleaned) ``` - + diff --git a/2025/day05.livemd b/2025/day05.livemd index 4de10ad..a0dd652 100644 --- a/2025/day05.livemd +++ b/2025/day05.livemd @@ -7,7 +7,7 @@ Mix.install([ ]) ``` -## Section +## Parse @@ -35,12 +35,20 @@ ingridients = |> Enum.map(&String.to_integer/1) ``` + + +## Part 1 + ```elixir Enum.count(ingridients, & &1 in fresh) ``` + + +## Part 2 + ```elixir Enum.count(fresh) ``` - + diff --git a/2025/day06.livemd b/2025/day06.livemd index cff294c..db2245f 100644 --- a/2025/day06.livemd +++ b/2025/day06.livemd @@ -27,6 +27,8 @@ ops = |> Enum.map(&String.to_atom/1) ``` + + ## Part 1 ```elixir @@ -40,6 +42,8 @@ tasks end) ``` + + ## Part 2 ```elixir @@ -61,4 +65,4 @@ tasks end) ``` - + diff --git a/2025/day07.livemd b/2025/day07.livemd index b195a18..1f17b1b 100644 --- a/2025/day07.livemd +++ b/2025/day07.livemd @@ -30,6 +30,8 @@ splitters = end) ``` + + ## Part 1 ```elixir @@ -92,11 +94,11 @@ Image.new!(width, height) import MapSet, only: [intersection: 2, difference: 2, union: 2] for x <- beams do - Image.Draw.point!(img, x, y, color: :green) + Image.Draw.point(img, x, y, color: :green) end for x <- splits do - Image.Draw.point!(img, x, y, color: :red) + Image.Draw.point(img, x, y, color: :red) end hits = intersection(beams, splits) @@ -106,14 +108,10 @@ Image.new!(width, height) beams end) - #for {row, y} <- Enum.with_index(splitters, 1), - # x <- row, - # do: Image.Draw.point!(img, x, y, color: :red) - img end) |> then(fn {:ok, img} -> img end) |> Image.resize!(5, interpolate: :nearest) ``` - +