Created
June 22, 2016 10:43
-
-
Save tomcha/a4dd81c44d07afb6ebae36bdcb3306e7 to your computer and use it in GitHub Desktop.
recursion6.rb
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
pro = Proc.new{|n| n % 2 == 0 ? true : false} | |
#list = [2, 4, 6, 8] | |
list = [3, 5, 7, 9] | |
def exists(list, pro) | |
if list.size == 0 | |
false | |
elsif list.size == 1 | |
pro.call(list.shift) | |
else | |
pro.call(list.shift) || exists(list, pro) | |
end | |
end | |
puts exists(list, pro) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment