From 08aab2ebc80c3f05437bd23581f5e725c732b325 Mon Sep 17 00:00:00 2001 From: Dustin Swan Date: Thu, 19 Dec 2024 22:15:17 -0700 Subject: [PATCH] Cleaning --- day18/main.exs | 37 ++----------------------------------- 1 file changed, 2 insertions(+), 35 deletions(-) diff --git a/day18/main.exs b/day18/main.exs index c80a5ac..d00e335 100644 --- a/day18/main.exs +++ b/day18/main.exs @@ -11,6 +11,7 @@ defmodule Day18 do map_list1 = Enum.take(map_list, 1024) + # create the grid as a map map1 = Enum.reduce(0..(height - 1), %{}, fn row, acc -> Enum.reduce(0..(width - 1), acc, fn col, acc2 -> @@ -29,10 +30,9 @@ defmodule Day18 do {_path, shortest} = walk(map1, q, dest, visited, [], 100_000_000_000, width, height) dbg(shortest) + # count up from 1024 and create a new map each time, until we create an impassable map part2 = Enum.reduce(1024..length(map_list), nil, fn idx, acc -> - dbg(idx) - if !is_nil(acc) do # exit early, we already found the coord acc @@ -57,7 +57,6 @@ defmodule Day18 do q = :queue.from_list([{start, 0, [{0, 0}]}]) res = walk(map, q, dest, visited, [], 100_000_000_000, width, height) - dbg(res) if is_nil(res) do List.last(map_list) @@ -112,38 +111,6 @@ defmodule Day18 do end end end - - defp render(map, location \\ nil, visited \\ %{}) do - width = Map.keys(map) |> Enum.map(&elem(&1, 1)) |> Enum.max() - height = Map.keys(map) |> Enum.map(&elem(&1, 0)) |> Enum.max() - - Enum.each(0..height, fn row -> - Enum.each(0..width, fn col -> - el = if Map.get(map, {col, row}, :wall) == :wall, do: "#", else: "." - - visited? = Map.has_key?(visited, {col, row}) - - formatted = - if location == {col, row} do - IO.ANSI.format([:red_background, "@"]) - else - if visited? do - IO.ANSI.format([:blue_background, el]) - else - el - end - end - - IO.write(formatted) - end) - - IO.write("\n") - end) - - IO.write("\n") - - map - end end Day18.run()