Skip to content

Instantly share code, notes, and snippets.

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