Skip to content

Instantly share code, notes, and snippets.

@varreli
Created May 8, 2014 20:00
Show Gist options
  • Save varreli/a737cbdb95f6c9ad6726 to your computer and use it in GitHub Desktop.
Save varreli/a737cbdb95f6c9ad6726 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]
#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 = 2.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