From: Paul Butcher Date: 2007-09-16T20:44:16+09:00 Subject: Re: Solving the Zurg puzzle in Ruby Frederick Cheung wrote: > Replacing > > def cost > who.collect(&:time).max > end > > with > > who.inject(0) { |current_max, toy| toy.time > current_max ? toy.time : > current_max } > > makes paul's solution run 5.5 times faster on my machine (in around 29 > seconds). Still slower than Brian's (which takes 24 seconds), but And replacing it with: who.max {|a, b| a.time <=> b.time}.time (which is actually the way that I wrote it initially - but I thought that the solution using collect was clearer!) gets my solution and Brian's running in vitually identical times. Paul -- Posted via http://www.ruby-forum.com/.