Created
March 2, 2015 07:37
-
-
Save rewinfrey/20b871313c00b69867a9 to your computer and use it in GitHub Desktop.
sample factorial y combinator in Ruby
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
result = -> (builder, number) { builder.call(builder, number) }.call( | |
-> (recurse, number) { | |
return 1 if number == 0 | |
return number * recurse.call(recurse, number - 1) | |
}, | |
5 | |
) | |
result # => 120 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment