Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
13
Task/Y-combinator/Groovy/y-combinator-1.groovy
Normal file
13
Task/Y-combinator/Groovy/y-combinator-1.groovy
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
def Y = { le -> ({ f -> f(f) })({ f -> le { x -> f(f)(x) } }) }
|
||||
|
||||
def factorial = Y { fac ->
|
||||
{ n -> n <= 2 ? n : n * fac(n - 1) }
|
||||
}
|
||||
|
||||
assert 2432902008176640000 == factorial(20G)
|
||||
|
||||
def fib = Y { fibStar ->
|
||||
{ n -> n <= 1 ? n : fibStar(n - 1) + fibStar(n - 2) }
|
||||
}
|
||||
|
||||
assert fib(10) == 55
|
||||
7
Task/Y-combinator/Groovy/y-combinator-2.groovy
Normal file
7
Task/Y-combinator/Groovy/y-combinator-2.groovy
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
def Y = { le -> ({ f -> f(f) })({ f -> le { Object[] args -> f(f)(*args) } }) }
|
||||
|
||||
def mul = Y { mulStar -> { a, b -> a ? b + mulStar(a - 1, b) : 0 } }
|
||||
|
||||
1.upto(10) {
|
||||
assert mul(it, 10) == it * 10
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue