Created
June 26, 2012 20:34
-
-
Save drewlesueur/2998748 to your computer and use it in GitHub Desktop.
need_y_combinator.coffee
This file contains hidden or 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
# normal factorial | |
factorial = (x) -> | |
if x == 1 then return 1 | |
return x * factorial(x - 1) | |
console.log factorial(6) #720 | |
# new factorial that doesn't reference itself | |
factorialGenerator = (fac) -> | |
(x) -> | |
if x == 1 then return 1 | |
return x * fac(x - 1) | |
# imagine the function Y exists | |
# what function Y would make this work equal 720? | |
console.log Y(factorialGenerator)(7) #720 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment