Skip to content

Instantly share code, notes, and snippets.

@tomcha
Created June 22, 2016 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomcha/a4dd81c44d07afb6ebae36bdcb3306e7 to your computer and use it in GitHub Desktop.
Save tomcha/a4dd81c44d07afb6ebae36bdcb3306e7 to your computer and use it in GitHub Desktop.
recursion6.rb
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