Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
1
Task/Y-combinator/SuperCollider/y-combinator-1.sc
Normal file
1
Task/Y-combinator/SuperCollider/y-combinator-1.sc
Normal file
|
|
@ -0,0 +1 @@
|
|||
y = { |f| { |x| f.(x.(x)) }.({ |x| f.(x.(x)) }) };
|
||||
41
Task/Y-combinator/SuperCollider/y-combinator-2.sc
Normal file
41
Task/Y-combinator/SuperCollider/y-combinator-2.sc
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// z-combinator
|
||||
|
||||
z = { |f| { |x| f.({ |args| x.(x).(args) }) }.({ |x| f.({ |args| x.(x).(args) }) }) };
|
||||
|
||||
// this can be also factored differently
|
||||
(
|
||||
y = { |f|
|
||||
{ |r| r.(r) }.(
|
||||
{ |x| f.({ |args| x.(x).(args) }) }
|
||||
)
|
||||
};
|
||||
)
|
||||
|
||||
// the same in a reduced form
|
||||
|
||||
(
|
||||
r = { |x| x.(x) };
|
||||
z = { |f| r.({ |y| f.(r.(y).(_)) }) };
|
||||
)
|
||||
|
||||
|
||||
// factorial
|
||||
k = { |f| { |x| if(x < 2, 1, { x * f.(x - 1) }) } };
|
||||
|
||||
g = z.(k);
|
||||
|
||||
g.(5) // 120
|
||||
|
||||
(1..10).collect(g) // [ 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800 ]
|
||||
|
||||
|
||||
|
||||
// fibonacci
|
||||
|
||||
k = { |f| { |x| if(x <= 2, 1, { f.(x - 1) + f.(x - 2) }) } };
|
||||
|
||||
g = z.(k);
|
||||
|
||||
g.(3)
|
||||
|
||||
(1..10).collect(g) // [ 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 ]
|
||||
Loading…
Add table
Add a link
Reference in a new issue