From 6eec3568f8316cba17ff9e59bb7e82ca7d3e1df5 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Fri, 6 Dec 2024 07:35:54 -0800 Subject: [PATCH] [2024][ruby][6.x] tweak conditions --- 2024/ruby/day_06.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 ?#