From 56ee9d38accaff04e615f3e19ae60bbcd60913c1 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Sun, 18 Dec 2016 16:53:32 -0800 Subject: [PATCH] [2016][ruby][17.1] --- 2016/ruby/day_17.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/2016/ruby/day_17.rb b/2016/ruby/day_17.rb index bfb6b38..74080a4 100644 --- a/2016/ruby/day_17.rb +++ b/2016/ruby/day_17.rb @@ -11,6 +11,8 @@ Maze = Struct.new(:passcode, :size) do state = states.shift yield state + next if state.location == [3,3] + hash = Digest::MD5.hexdigest("#{passcode}#{state.path}")[0,4] open_doors = %i[ U D L R ].select.with_index {|_, index| 'bcdef'.include?(hash[index]) @@ -39,6 +41,6 @@ Maze = Struct.new(:passcode, :size) do end end -p Maze.new('yjjvjgan', 4).walk.find {|state| +p Maze.new('yjjvjgan', 4).walk.select {|state| state.location == [3, 3] -} +}.map(&:path).map(&:length).max