From 8ceaee32a0cac77c11df36f2d55b3e7a6522fb0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Niemier?= <~@hauleth.dev> Date: Sat, 6 Dec 2025 09:29:38 +0100 Subject: [PATCH] Add drawing of the board for day 07 of 2025 --- 2025/day07.livemd | 50 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/2025/day07.livemd b/2025/day07.livemd index 65cfc59..b195a18 100644 --- a/2025/day07.livemd +++ b/2025/day07.livemd @@ -44,6 +44,8 @@ Enum.reduce(splitters, {MapSet.new([start_col]), 0}, fn splits, {beams, count} - end) ``` + + ## Part 2 ```elixir @@ -68,4 +70,50 @@ end) |> Enum.sum_by(&elem(&1, 1)) ``` - + + +## Image + +```elixir +height = length([start | rest]) +width = byte_size(start) + +{height, width} +``` + +```elixir +Image.new!(width, height) +|> Image.mutate(fn img -> + Image.Draw.point!(img, start_col, 0, color: :yellow) + + splitters + |> Enum.with_index(1) + |> Enum.reduce(MapSet.new([start_col]), fn {splits, y}, beams -> + import MapSet, only: [intersection: 2, difference: 2, union: 2] + + for x <- beams do + Image.Draw.point!(img, x, y, color: :green) + end + + for x <- splits do + Image.Draw.point!(img, x, y, color: :red) + end + + hits = intersection(beams, splits) + new_beams = for hit <- hits, dx <- [-1, 1], into: MapSet.new(), do: hit + dx + beams = beams |> difference(hits) |> union(new_beams) + + 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) +``` + + -- 2.51.2