From: James Gray Date: 2008-09-30T07:11:25+09:00 Subject: Re: [QUIZ] Cookie Monster (#178) On Sep 26, 2008, at 9:53 AM, Matthew Moss wrote: > ## Cookie Monster (#178) My simple search: #!/usr/bin/env ruby -wKU def search(field, current = {:x => 0, :y => 0, :cookies => field[0] [0], :path => ""}) %w[E S].map do |direction| new_best = Marshal.load(Marshal.dump(current)) if direction == "E" new_best[:x] += 1 next new_best if new_best[:x] >= field.first.length else new_best[:y] += 1 next new_best if new_best[:y] >= field.length end next new_best if field[new_best[:y]][new_best[:x]] < 0 new_best[:cookies] += field[new_best[:y]][new_best[:x]] new_best[:path] << direction search(field, new_best) end.max { |a, b| a[:cookies] <=> b[:cookies] } end puzzle = <