Created
May 8, 2014 20:19
-
-
Save varreli/2e58733778876e8e294c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = 20.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