[2016][ruby][24.0] remove infinte looping
change yuqzznktrowrqppuwqxnwluumxxwzslq
commit 5910dc2de1393d687483aaa94d3383adc3c06194
author Alpha Chen <alpha.chen@gmail.com>
date
parent zrvtnwso
diff --git a/2016/ruby/day_24.rb b/2016/ruby/day_24.rb
index 778e699..66091fb 100644
--- a/2016/ruby/day_24.rb
+++ b/2016/ruby/day_24.rb
@@ -11,6 +11,10 @@ class Solver
     loop do
       location = current[0]
       break if location == to
+      if seen.include?(location)
+        current = queue.shift
+        next
+      end
 
       seen << location
 
@@ -95,6 +99,7 @@ if __FILE__ == $0
     .map {|route|
       [route, route.each_cons(2).map {|a,b| hash[[a,b]] }.inject(:+)]
     }.sort_by(&:last)
+    .first
 end
 
 require 'minitest'