[2023][ruby][17.2]
change umnkymrvqolrmwrsoyvxnunoywryuzro
commit 4668be7316d8a9591ef4ce945048da050992ef08
author Alpha Chen <alpha@kejadlen.dev>
date
parent qlotvnlm
diff --git a/2023/ruby/day_17.rb b/2023/ruby/day_17.rb
index e09ef49..36fc0c8 100644
--- a/2023/ruby/day_17.rb
+++ b/2023/ruby/day_17.rb
@@ -32,13 +32,17 @@ loop do
   frontier.sort_by! { visited.fetch(_1) }
   current = frontier.shift
 
+  nexts = []
+
   # turn left and right
-  nexts = [current.dir.reverse, current.dir.reverse.map { -_1 }].map {|turn|
-    Node.new(current.pos.zip(turn).map { _1 + _2 }, turn, 1)
-  }
+  if current.continued > 3
+    nexts.concat([current.dir.reverse, current.dir.reverse.map { -_1 }].map {|turn|
+      Node.new(current.pos.zip(turn).map { _1 + _2 }, turn, 1)
+    })
+  end
 
   # keep going?
-  if current.continued < 3
+  if current.continued < 10
     nexts << Node.new(
       current.pos.zip(current.dir).map { _1 + _2 },
       current.dir,
@@ -46,7 +50,7 @@ loop do
     )
   end
 
-  if found = nexts.find { _1.pos == dest }
+  if found = nexts.find { _1.pos == dest && (4..10).cover?(_1.continued) }
     p visited.fetch(current) + map.fetch(dest)
     exit
   end