Skip to content

Instantly share code, notes, and snippets.

@varreli
Created May 8, 2014 00:01
Show Gist options
  • Save varreli/4bc2089a396b954371a4 to your computer and use it in GitHub Desktop.
Save varreli/4bc2089a396b954371a4 to your computer and use it in GitHub Desktop.
def rock_judger(rocks_arr)
if rocks_arr.length <= 2 # the base case
a = rocks_arr[0]
b = rocks_arr[-1]
else
a = rock_judger(rocks_arr.slice!(0,rocks_arr.length/2))
b = rock_judger(rocks_arr)
end
return a > b ? a : b
end
rocks = 30.times.map{rand(200) + 1}
puts rocks.join(', ')
puts "Heaviest rock is: #{rock_judger(rocks)}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment