diff --git a/2024/ruby/day_06.rb b/2024/ruby/day_06.rb index 8ef0cf0..3284573 100644 --- a/2024/ruby/day_06.rb +++ b/2024/ruby/day_06.rb @@ -21,10 +21,13 @@ def patrol(lab) loop do pos, dir = path.last peek = pos.zip(dir).map {|i,di| i + di } + + return path unless lab.has_key?(peek) + raise Loop if seen.include?([peek, dir]) seen << [peek, dir] - case lab.fetch(peek, nil) + case lab.fetch(peek) when ?., ?^ path << [peek, dir] when ?#