rosetta-code.y-combinator: add ackerman functions to demonstrate several inputs
parent
e980e26f70
commit
cc621ee5ee
|
@ -3,4 +3,5 @@ IN: rosetta-code.y-combinator
|
||||||
|
|
||||||
[ 120 ] [ 5 [ almost-fac ] Y call ] unit-test
|
[ 120 ] [ 5 [ almost-fac ] Y call ] unit-test
|
||||||
[ 8 ] [ 6 [ almost-fib ] Y call ] unit-test
|
[ 8 ] [ 6 [ almost-fib ] Y call ] unit-test
|
||||||
|
[ 61 ] [ 3 3 [ almost-ack ] Y call ] unit-test
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
! Copyright (c) 2012 Anonymous
|
! Copyright (c) 2012 Anonymous
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: fry kernel math ;
|
USING: combinators fry kernel locals math ;
|
||||||
IN: rosetta-code.y-combinator
|
IN: rosetta-code.y-combinator
|
||||||
|
|
||||||
! http://rosettacode.org/wiki/Y_combinator
|
! http://rosettacode.org/wiki/Y_combinator
|
||||||
|
@ -31,3 +31,13 @@ IN: rosetta-code.y-combinator
|
||||||
! fibonacci sequence
|
! fibonacci sequence
|
||||||
: almost-fib ( quot -- quot )
|
: almost-fib ( quot -- quot )
|
||||||
'[ dup 2 >= [ 1 2 [ - @ ] bi-curry@ bi + ] when ] ;
|
'[ dup 2 >= [ 1 2 [ - @ ] bi-curry@ bi + ] when ] ;
|
||||||
|
|
||||||
|
! Ackermann–Péter function
|
||||||
|
:: almost-ack ( quot -- quot )
|
||||||
|
[
|
||||||
|
{
|
||||||
|
{ [ over zero? ] [ nip 1 + ] }
|
||||||
|
{ [ dup zero? ] [ [ 1 - ] [ drop 1 ] bi* quot call ] }
|
||||||
|
[ [ drop 1 - ] [ 1 - quot call ] 2bi quot call ]
|
||||||
|
} cond
|
||||||
|
] ;
|
||||||
|
|
Loading…
Reference in New Issue