diff --git a/2024/day14.exs b/2024/day14.exs index 0f163de..0166db2 100755 --- a/2024/day14.exs +++ b/2024/day14.exs @@ -59,10 +59,10 @@ defmodule Day14 do # manually: noticed things looked suspicious after 27 seconds # also noticed that repeated every 101 seconds # Checked each 101 second jump until found the above tree - tick_forever(robots, size_x, size_y) + find_tree(robots, size_x, size_y) end - def tick_forever(robots, size_x, size_y, count \\ 27, acc \\ 27) do + def find_tree(robots, size_x, size_y, count \\ 27, acc \\ 27) do robots = tick(robots, size_x, size_y, count) robomap = MapSet.new(robots, fn [x, y, _, _] -> {x, y} end) @@ -78,9 +78,13 @@ defmodule Day14 do IO.puts("|") end - IO.gets("#{acc} tree?") + line = IO.gets("#{acc} tree [y/N]?") - tick_forever(robots, size_x, size_y, 101, acc + 101) + if line |> String.trim() |> String.downcase() == "y" do + acc + else + find_tree(robots, size_x, size_y, 101, acc + 101) + end end def tick(robots, size_x, size_y, times) do