Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
112
Task/Ackermann-function/68000-Assembly/ackermann-function.68000
Normal file
112
Task/Ackermann-function/68000-Assembly/ackermann-function.68000
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
;
|
||||
; Ackermann function for Motorola 68000 under AmigaOs 2+ by Thorham
|
||||
;
|
||||
; Set stack space to 60000 for m = 3, n = 5.
|
||||
;
|
||||
; The program will print the ackermann values for the range m = 0..3, n = 0..5
|
||||
;
|
||||
_LVOOpenLibrary equ -552
|
||||
_LVOCloseLibrary equ -414
|
||||
_LVOVPrintf equ -954
|
||||
|
||||
m equ 3 ; Nr of iterations for the main loop.
|
||||
n equ 5 ; Do NOT set them higher, or it will take hours to complete on
|
||||
; 68k, not to mention that the stack usage will become astronomical.
|
||||
; Perhaps n can be a little higher... If you do increase the ranges
|
||||
; then don't forget to increase the stack size.
|
||||
|
||||
execBase=4
|
||||
|
||||
start
|
||||
move.l execBase,a6
|
||||
|
||||
lea dosName,a1
|
||||
moveq #36,d0
|
||||
jsr _LVOOpenLibrary(a6)
|
||||
move.l d0,dosBase
|
||||
beq exit
|
||||
|
||||
move.l dosBase,a6
|
||||
lea printfArgs,a2
|
||||
|
||||
clr.l d3 ; m
|
||||
.loopn
|
||||
clr.l d4 ; n
|
||||
.loopm
|
||||
bsr ackermann
|
||||
|
||||
move.l d3,0(a2)
|
||||
move.l d4,4(a2)
|
||||
move.l d5,8(a2)
|
||||
move.l #outString,d1
|
||||
move.l a2,d2
|
||||
jsr _LVOVPrintf(a6)
|
||||
|
||||
addq.l #1,d4
|
||||
cmp.l #n,d4
|
||||
ble .loopm
|
||||
|
||||
addq.l #1,d3
|
||||
cmp.l #m,d3
|
||||
ble .loopn
|
||||
|
||||
exit
|
||||
move.l execBase,a6
|
||||
move.l dosBase,a1
|
||||
jsr _LVOCloseLibrary(a6)
|
||||
rts
|
||||
;
|
||||
; ackermann function
|
||||
;
|
||||
; in:
|
||||
;
|
||||
; d3 = m
|
||||
; d4 = n
|
||||
;
|
||||
; out:
|
||||
;
|
||||
; d5 = ans
|
||||
;
|
||||
ackermann
|
||||
move.l d3,-(sp)
|
||||
move.l d4,-(sp)
|
||||
|
||||
tst.l d3
|
||||
bne .l1
|
||||
move.l d4,d5
|
||||
addq.l #1,d5
|
||||
bra .return
|
||||
.l1
|
||||
tst.l d4
|
||||
bne .l2
|
||||
subq.l #1,d3
|
||||
moveq #1,d4
|
||||
bsr ackermann
|
||||
bra .return
|
||||
.l2
|
||||
subq.l #1,d4
|
||||
bsr ackermann
|
||||
move.l d5,d4
|
||||
subq.l #1,d3
|
||||
bsr ackermann
|
||||
|
||||
.return
|
||||
move.l (sp)+,d4
|
||||
move.l (sp)+,d3
|
||||
rts
|
||||
;
|
||||
; variables
|
||||
;
|
||||
dosBase
|
||||
dc.l 0
|
||||
|
||||
printfArgs
|
||||
dcb.l 3
|
||||
;
|
||||
; strings
|
||||
;
|
||||
dosName
|
||||
dc.b "dos.library",0
|
||||
|
||||
outString
|
||||
dc.b "ackermann (%ld,%ld) is: %ld",10,0
|
||||
75
Task/Ackermann-function/8th/ackermann-function.8th
Normal file
75
Task/Ackermann-function/8th/ackermann-function.8th
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
\ Ackermann function, illustrating use of "memoization".
|
||||
|
||||
\ Memoization is a technique whereby intermediate computed values are stored
|
||||
\ away against later need. It is particularly valuable when calculating those
|
||||
\ values is time or resource intensive, as with the Ackermann function.
|
||||
|
||||
\ make the stack much bigger so this can complete!
|
||||
100000 stack-size
|
||||
|
||||
\ This is where memoized values are stored:
|
||||
{} var, dict
|
||||
|
||||
\ Simple accessor words
|
||||
: dict! \ "key" val --
|
||||
dict @ -rot m:! drop ;
|
||||
|
||||
: dict@ \ "key" -- val
|
||||
dict @ swap m:@ nip ;
|
||||
|
||||
defer: ack1
|
||||
|
||||
\ We just jam the string representation of the two numbers together for a key:
|
||||
: makeKey \ m n -- m n key
|
||||
2dup >s swap >s s:+ ;
|
||||
|
||||
: ack2 \ m n -- A
|
||||
makeKey dup
|
||||
dict@ null?
|
||||
if \ can't find key in dict
|
||||
\ m n key null
|
||||
drop \ m n key
|
||||
-rot \ key m n
|
||||
ack1 \ key A
|
||||
tuck \ A key A
|
||||
dict! \ A
|
||||
else \ found value
|
||||
\ m n key value
|
||||
>r drop 2drop r>
|
||||
then ;
|
||||
|
||||
: ack \ m n -- A
|
||||
over not
|
||||
if
|
||||
nip n:1+
|
||||
else
|
||||
dup not
|
||||
if
|
||||
drop n:1- 1 ack2
|
||||
else
|
||||
over swap n:1- ack2
|
||||
swap n:1- swap ack2
|
||||
then
|
||||
then ;
|
||||
|
||||
' ack is ack1
|
||||
|
||||
: ackOf \ m n --
|
||||
2dup
|
||||
"Ack(" . swap . ", " . . ") = " . ack . cr ;
|
||||
|
||||
|
||||
0 0 ackOf
|
||||
0 4 ackOf
|
||||
1 0 ackOf
|
||||
1 1 ackOf
|
||||
2 1 ackOf
|
||||
2 2 ackOf
|
||||
3 1 ackOf
|
||||
3 3 ackOf
|
||||
4 0 ackOf
|
||||
|
||||
\ this last requires a very large data stack. So start 8th with a parameter '-k 100000'
|
||||
4 1 ackOf
|
||||
|
||||
bye
|
||||
54
Task/Ackermann-function/ERRE/ackermann-function.erre
Normal file
54
Task/Ackermann-function/ERRE/ackermann-function.erre
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
PROGRAM ACKERMAN
|
||||
|
||||
!
|
||||
! computes Ackermann function
|
||||
! (second version for rosettacode.org)
|
||||
!
|
||||
|
||||
!$INTEGER
|
||||
|
||||
DIM STACK[10000]
|
||||
|
||||
!$INCLUDE="PC.LIB"
|
||||
|
||||
PROCEDURE ACK(M,N->N)
|
||||
LOOP
|
||||
CURSOR_SAVE(->CURX%,CURY%)
|
||||
LOCATE(8,1)
|
||||
PRINT("Livello Stack:";S;" ")
|
||||
LOCATE(CURY%,CURX%)
|
||||
IF M<>0 THEN
|
||||
IF N<>0 THEN
|
||||
STACK[S]=M
|
||||
S+=1
|
||||
N-=1
|
||||
ELSE
|
||||
M-=1
|
||||
N+=1
|
||||
END IF
|
||||
CONTINUE LOOP
|
||||
ELSE
|
||||
N+=1
|
||||
S-=1
|
||||
END IF
|
||||
IF S<>0 THEN
|
||||
M=STACK[S]
|
||||
M-=1
|
||||
CONTINUE LOOP
|
||||
ELSE
|
||||
EXIT PROCEDURE
|
||||
END IF
|
||||
END LOOP
|
||||
END PROCEDURE
|
||||
|
||||
BEGIN
|
||||
PRINT(CHR$(12);)
|
||||
FOR X=0 TO 3 DO
|
||||
FOR Y=0 TO 9 DO
|
||||
S=1
|
||||
ACK(X,Y->ANS)
|
||||
PRINT(ANS;)
|
||||
END FOR
|
||||
PRINT
|
||||
END FOR
|
||||
END PROGRAM
|
||||
38
Task/Ackermann-function/Ezhil/ackermann-function.ezhil
Normal file
38
Task/Ackermann-function/Ezhil/ackermann-function.ezhil
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
நிரல்பாகம் அகெர்மன்(முதலெண், இரண்டாமெண்)
|
||||
|
||||
@((முதலெண் < 0) || (இரண்டாமெண் < 0)) ஆனால்
|
||||
|
||||
பின்கொடு -1
|
||||
|
||||
முடி
|
||||
|
||||
@(முதலெண் == 0) ஆனால்
|
||||
|
||||
பின்கொடு இரண்டாமெண்+1
|
||||
|
||||
முடி
|
||||
|
||||
@((முதலெண் > 0) && (இரண்டாமெண் == 00)) ஆனால்
|
||||
|
||||
பின்கொடு அகெர்மன்(முதலெண் - 1, 1)
|
||||
|
||||
முடி
|
||||
|
||||
பின்கொடு அகெர்மன்(முதலெண் - 1, அகெர்மன்(முதலெண், இரண்டாமெண் - 1))
|
||||
|
||||
முடி
|
||||
|
||||
அ = int(உள்ளீடு("ஓர் எண்ணைத் தாருங்கள், அது பூஜ்ஜியமாகவோ, அதைவிடப் பெரியதாக இருக்கலாம்: "))
|
||||
ஆ = int(உள்ளீடு("அதேபோல் இன்னோர் எண்ணைத் தாருங்கள், இதுவும் பூஜ்ஜியமாகவோ, அதைவிடப் பெரியதாகவோ இருக்கலாம்: "))
|
||||
|
||||
விடை = அகெர்மன்(அ, ஆ)
|
||||
|
||||
@(விடை < 0) ஆனால்
|
||||
|
||||
பதிப்பி "தவறான எண்களைத் தந்துள்ளீர்கள்!"
|
||||
|
||||
இல்லை
|
||||
|
||||
பதிப்பி "நீங்கள் தந்த எண்களுக்கான அகர்மென் மதிப்பு: ", விடை
|
||||
|
||||
முடி
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
' version 28-10-2016
|
||||
' compile with: fbc -s console
|
||||
' to do A(4, 2) the stack size needs to be increased
|
||||
' compile with: fbc -s console -t 2000
|
||||
|
||||
Function ackerman (m As Long, n As Long) As Long
|
||||
|
||||
If m = 0 Then ackerman = n +1
|
||||
|
||||
If m > 0 Then
|
||||
If n = 0 Then
|
||||
ackerman = ackerman(m -1, 1)
|
||||
Else
|
||||
If n > 0 Then
|
||||
ackerman = ackerman(m -1, ackerman(m, n -1))
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
End Function
|
||||
|
||||
' ------=< MAIN >=------
|
||||
|
||||
Dim As Long m, n
|
||||
Print
|
||||
|
||||
For m = 0 To 4
|
||||
Print Using "###"; m;
|
||||
For n = 0 To 10
|
||||
' A(4, 1) or higher will run out of stack memory (default 1M)
|
||||
' change n = 1 to n = 2 to calculate A(4, 2), increase stack!
|
||||
If m = 4 And n = 1 Then Exit For
|
||||
Print Using "######"; ackerman(m, n);
|
||||
Next
|
||||
Print
|
||||
Next
|
||||
|
||||
' empty keyboard buffer
|
||||
While InKey <> "" : Wend
|
||||
Print : Print "hit any key to end program"
|
||||
Sleep
|
||||
End
|
||||
7
Task/Ackermann-function/FunL/ackermann-function.funl
Normal file
7
Task/Ackermann-function/FunL/ackermann-function.funl
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
def
|
||||
ackermann( 0, n ) = n + 1
|
||||
ackermann( m, 0 ) = ackermann( m - 1, 1 )
|
||||
ackermann( m, n ) = ackermann( m - 1, ackermann(m, n - 1) )
|
||||
|
||||
for m <- 0..3, n <- 0..4
|
||||
printf( 'Ackermann( %d, %d ) = %d\n', m, n, ackermann(m, n) )
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
fun ackermann(m: int, n: int): int =
|
||||
if m == 0 then n + 1
|
||||
else if n == 0 then ackermann(m-1, 1)
|
||||
else ackermann(m - 1, ackermann(m, n-1))
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
include "ConsoleWindow"
|
||||
|
||||
def tab 1
|
||||
|
||||
begin globals
|
||||
dim as container gC
|
||||
end globals
|
||||
|
||||
def fn Ackerman( m as long, n as long ) as long
|
||||
|
||||
local fn Ackerman( m as long, n as long ) as long
|
||||
dim as long result
|
||||
|
||||
if m == 0 then result = n + 1 : exit fn
|
||||
|
||||
if ( n == 0 )
|
||||
result = fn Ackerman( m - 1, 1 )
|
||||
exit fn
|
||||
end if
|
||||
|
||||
result = fn Ackerman( m - 1, fn Ackerman(m, n - 1) )
|
||||
end fn = result
|
||||
|
||||
dim as long n, m
|
||||
|
||||
/*
|
||||
Cache response in global string container to speed
|
||||
processing rather printing each iteration.
|
||||
*/
|
||||
for m = 0 to 3
|
||||
for n = 0 to 10
|
||||
gC += "fn ackerman(" + str$(m) + "," + str$(n) + " ) =" + Str$( fn Ackerman( m, n ) ) + chr$(13)
|
||||
next
|
||||
next
|
||||
|
||||
print gC
|
||||
4
Task/Ackermann-function/Idris/ackermann-function.idris
Normal file
4
Task/Ackermann-function/Idris/ackermann-function.idris
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
A : Nat -> Nat -> Nat
|
||||
A Z n = S n
|
||||
A (S m) Z = A m (S Z)
|
||||
A (S m) (S n) = A m (A (S m) n)
|
||||
4
Task/Ackermann-function/LFE/ackermann-function.lfe
Normal file
4
Task/Ackermann-function/LFE/ackermann-function.lfe
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
(defun ackermann
|
||||
((0 n) (+ n 1))
|
||||
((m 0) (ackermann (- m 1) 1))
|
||||
((m n) (ackermann (- m 1) (ackermann m (- n 1)))))
|
||||
15
Task/Ackermann-function/Lasso/ackermann-function.lasso
Normal file
15
Task/Ackermann-function/Lasso/ackermann-function.lasso
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/lasso9
|
||||
|
||||
define ackermann(m::integer, n::integer) => {
|
||||
if(#m == 0) => {
|
||||
return ++#n
|
||||
else(#n == 0)
|
||||
return ackermann(--#m, 1)
|
||||
else
|
||||
return ackermann(#m-1, ackermann(#m, --#n))
|
||||
}
|
||||
}
|
||||
|
||||
with x in generateSeries(1,3),
|
||||
y in generateSeries(0,8,2)
|
||||
do stdoutnl(#x+', '#y+': ' + ackermann(#x, #y))
|
||||
10
Task/Ackermann-function/LiveCode/ackermann-function.livecode
Normal file
10
Task/Ackermann-function/LiveCode/ackermann-function.livecode
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
function ackermann m,n
|
||||
switch
|
||||
Case m = 0
|
||||
return n + 1
|
||||
Case (m > 0 And n = 0)
|
||||
return ackermann((m - 1), 1)
|
||||
Case (m > 0 And n > 0)
|
||||
return ackermann((m - 1), ackermann(m, (n - 1)))
|
||||
end switch
|
||||
end ackermann
|
||||
5
Task/Ackermann-function/Luck/ackermann-function.luck
Normal file
5
Task/Ackermann-function/Luck/ackermann-function.luck
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
function ackermann(m: int, n: int): int = (
|
||||
if m==0 then n+1
|
||||
else if n==0 then ackermann(m-1,1)
|
||||
else ackermann(m-1,ackermann(m,n-1))
|
||||
)
|
||||
7
Task/Ackermann-function/Nim/ackermann-function-1.nim
Normal file
7
Task/Ackermann-function/Nim/ackermann-function-1.nim
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
proc Ackermann(m, n: int64): int64 =
|
||||
if m == 0:
|
||||
result = n + 1
|
||||
elif n == 0:
|
||||
result = Ackermann(m - 1, 1)
|
||||
else:
|
||||
result = Ackermann(m - 1, Ackermann(m, n - 1))
|
||||
32
Task/Ackermann-function/Nim/ackermann-function-2.nim
Normal file
32
Task/Ackermann-function/Nim/ackermann-function-2.nim
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
from strutils import parseInt
|
||||
|
||||
proc ackermann(m,n: int): int =
|
||||
var res: int
|
||||
if m == 0:
|
||||
res += n + 1
|
||||
elif m > 0 and n == 0:
|
||||
res += ackermann(m-1, 1)
|
||||
elif m > 0 and n > 0:
|
||||
res += ackermann(m-1, ackermann(m, n-1))
|
||||
return res
|
||||
|
||||
proc getnumber(): int =
|
||||
try:
|
||||
parseInt(readLine(stdin))
|
||||
except EInvalidValue:
|
||||
echo("Please enter an integer: ")
|
||||
getnumber()
|
||||
|
||||
echo("First number please: ")
|
||||
var first: int = getnumber()
|
||||
while first < 0:
|
||||
echo("Please enter a non-negative integer value.")
|
||||
first = getnumber()
|
||||
|
||||
echo("Second number please: ")
|
||||
var second: int = getnumber()
|
||||
while second < 0:
|
||||
echo("Please enter a non-negative integer value.")
|
||||
second = getnumber()
|
||||
|
||||
echo("Result: " & $ackermann(first, second))
|
||||
4
Task/Ackermann-function/Oforth/ackermann-function.oforth
Normal file
4
Task/Ackermann-function/Oforth/ackermann-function.oforth
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
: A(m, n)
|
||||
m ifZero: [ n 1+ return ]
|
||||
n ifZero: [ A(m 1-, 1) return ]
|
||||
A(m 1-, A(m, n 1-)) ;
|
||||
37
Task/Ackermann-function/Phix/ackermann-function.phix
Normal file
37
Task/Ackermann-function/Phix/ackermann-function.phix
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
--
|
||||
-- Ackermann.exw
|
||||
-- =============
|
||||
--
|
||||
-- optimised. still no bignum library, so ack(4,2), which is power(2,65536)-3, which is
|
||||
-- apparently 19729 digits, and any above, are beyond (the CPU/FPU hardware) and this.
|
||||
-- (replaced ack(atom,atom) with ack(int,int) since the former fares no better.)
|
||||
|
||||
function ack(integer m, integer n)
|
||||
if m=0 then
|
||||
return n+1
|
||||
elsif m=1 then
|
||||
return n+2
|
||||
elsif m=2 then
|
||||
return 2*n+3
|
||||
elsif m=3 then
|
||||
return power(2,n+3)-3
|
||||
elsif m>0 and n=0 then
|
||||
return ack(m-1,1)
|
||||
else
|
||||
return ack(m-1,ack(m,n-1))
|
||||
end if
|
||||
end function
|
||||
|
||||
procedure Ackermann()
|
||||
for i=0 to 3 do
|
||||
for j=0 to 10 do
|
||||
printf(1,"%5d",ack(i,j))
|
||||
end for
|
||||
puts(1,"\n")
|
||||
end for
|
||||
printf(1,"ack(4,1) %5d\n",ack(4,1))
|
||||
-- printf(1,"ack(4,2) %5d\n",ack(4,2)) -- power function overflow
|
||||
if getc(0) then end if
|
||||
end procedure
|
||||
|
||||
Ackermann()
|
||||
11
Task/Ackermann-function/Potion/ackermann-function.potion
Normal file
11
Task/Ackermann-function/Potion/ackermann-function.potion
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
ack = (m, n):
|
||||
if (m == 0): n + 1
|
||||
. elsif (n == 0): ack(m - 1, 1)
|
||||
. else: ack(m - 1, ack(m, n - 1)).
|
||||
.
|
||||
|
||||
4 times(m):
|
||||
7 times(n):
|
||||
ack(m, n) print
|
||||
" " print.
|
||||
"\n" print.
|
||||
19
Task/Ackermann-function/Ring/ackermann-function.ring
Normal file
19
Task/Ackermann-function/Ring/ackermann-function.ring
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
for m = 0 to 3
|
||||
for n = 0 to 4
|
||||
see "Ackermann(" + m + ", " + n + ") = " + Ackermann(m, n) + nl
|
||||
next
|
||||
next
|
||||
|
||||
func Ackermann m, n
|
||||
if m > 0
|
||||
if n > 0
|
||||
return Ackermann(m - 1, Ackermann(m, n - 1))
|
||||
but n = 0
|
||||
return Ackermann(m - 1, 1)
|
||||
ok
|
||||
but m = 0
|
||||
if n >= 0
|
||||
return n + 1
|
||||
ok
|
||||
ok
|
||||
Raise("Incorrect Numerical input !!!")
|
||||
11
Task/Ackermann-function/SPAD/ackermann-function.spad
Normal file
11
Task/Ackermann-function/SPAD/ackermann-function.spad
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
NNI ==> NonNegativeInteger
|
||||
|
||||
A:(NNI,NNI) -> NNI
|
||||
|
||||
A(m,n) ==
|
||||
m=0 => n+1
|
||||
m>0 and n=0 => A(m-1,1)
|
||||
m>0 and n>0 => A(m-1,A(m,n-1))
|
||||
|
||||
-- Example
|
||||
matrix [[A(i,j) for i in 0..3] for j in 0..3]
|
||||
5
Task/Ackermann-function/Shen/ackermann-function.shen
Normal file
5
Task/Ackermann-function/Shen/ackermann-function.shen
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
(define ack
|
||||
0 N -> (+ N 1)
|
||||
M 0 -> (ack (- M 1) 1)
|
||||
M N -> (ack (- M 1)
|
||||
(ack M (- N 1))))
|
||||
5
Task/Ackermann-function/Sidef/ackermann-function-1.sidef
Normal file
5
Task/Ackermann-function/Sidef/ackermann-function-1.sidef
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
func A(m, n) {
|
||||
m == 0 ? (n + 1)
|
||||
: (n == 0 ? (A(m - 1, 1))
|
||||
: (A(m - 1, A(m, n - 1))));
|
||||
}
|
||||
3
Task/Ackermann-function/Sidef/ackermann-function-2.sidef
Normal file
3
Task/Ackermann-function/Sidef/ackermann-function-2.sidef
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
func A((0), n) { n + 1 }
|
||||
func A(m, (0)) { A(m - 1, 1) }
|
||||
func A(m, n) { A(m-1, A(m, n-1)) }
|
||||
1
Task/Ackermann-function/Sidef/ackermann-function-3.sidef
Normal file
1
Task/Ackermann-function/Sidef/ackermann-function-3.sidef
Normal file
|
|
@ -0,0 +1 @@
|
|||
say A(3, 2); # prints: 29
|
||||
9
Task/Ackermann-function/Swift/ackermann-function.swift
Normal file
9
Task/Ackermann-function/Swift/ackermann-function.swift
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
func ackerman(m:Int, n:Int) -> Int {
|
||||
if m == 0 {
|
||||
return n+1
|
||||
} else if n == 0 {
|
||||
return ackerman(m-1, 1)
|
||||
} else {
|
||||
return ackerman(m-1, ackerman(m, n-1))
|
||||
}
|
||||
}
|
||||
7
Task/Ackermann-function/Wart/ackermann-function.wart
Normal file
7
Task/Ackermann-function/Wart/ackermann-function.wart
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
def (ackermann m n)
|
||||
(if m=0
|
||||
n+1
|
||||
n=0
|
||||
(ackermann m-1 1)
|
||||
:else
|
||||
(ackermann m-1 (ackermann m n-1)))
|
||||
7
Task/Ackermann-function/Wren/ackermann-function.wren
Normal file
7
Task/Ackermann-function/Wren/ackermann-function.wren
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
// To use recursion definition and declaration must be on separate lines
|
||||
var Ackermann
|
||||
Ackermann = Fn.new {|m, n|
|
||||
if (m == 0) return n + 1
|
||||
if (n == 0) return Ackermann.call(m - 1, 1)
|
||||
return Ackermann.call(m - 1, Ackermann.call(m, n - 1))
|
||||
}
|
||||
5
Task/Ackermann-function/XLISP/ackermann-function-1.xlisp
Normal file
5
Task/Ackermann-function/XLISP/ackermann-function-1.xlisp
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
(defun ackermann (m n)
|
||||
(cond
|
||||
((= m 0) (+ n 1))
|
||||
((= n 0) (ackermann (- m 1) 1))
|
||||
(t (ackermann (- m 1) (ackermann m (- n 1))))))
|
||||
1
Task/Ackermann-function/XLISP/ackermann-function-2.xlisp
Normal file
1
Task/Ackermann-function/XLISP/ackermann-function-2.xlisp
Normal file
|
|
@ -0,0 +1 @@
|
|||
(print (ackermann 3 9))
|
||||
1
Task/Ackermann-function/XLISP/ackermann-function-3.xlisp
Normal file
1
Task/Ackermann-function/XLISP/ackermann-function-3.xlisp
Normal file
|
|
@ -0,0 +1 @@
|
|||
(print (ackermann 4 1))
|
||||
7
Task/Ackermann-function/jq/ackermann-function-1.jq
Normal file
7
Task/Ackermann-function/jq/ackermann-function-1.jq
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# input: [m,n]
|
||||
def ack:
|
||||
.[0] as $m | .[1] as $n
|
||||
| if $m == 0 then $n + 1
|
||||
elif $n == 0 then [$m-1, 1] | ack
|
||||
else [$m-1, ([$m, $n-1 ] | ack)] | ack
|
||||
end ;
|
||||
3
Task/Ackermann-function/jq/ackermann-function-2.jq
Normal file
3
Task/Ackermann-function/jq/ackermann-function-2.jq
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
range(0;5) as $i
|
||||
| range(0; if $i > 3 then 1 else 6 end) as $j
|
||||
| "A(\($i),\($j)) = \( [$i,$j] | ack )"
|
||||
26
Task/Ackermann-function/jq/ackermann-function-3.jq
Normal file
26
Task/Ackermann-function/jq/ackermann-function-3.jq
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
# jq -n -r -f ackermann.jq
|
||||
A(0,0) = 1
|
||||
A(0,1) = 2
|
||||
A(0,2) = 3
|
||||
A(0,3) = 4
|
||||
A(0,4) = 5
|
||||
A(0,5) = 6
|
||||
A(1,0) = 2
|
||||
A(1,1) = 3
|
||||
A(1,2) = 4
|
||||
A(1,3) = 5
|
||||
A(1,4) = 6
|
||||
A(1,5) = 7
|
||||
A(2,0) = 3
|
||||
A(2,1) = 5
|
||||
A(2,2) = 7
|
||||
A(2,3) = 9
|
||||
A(2,4) = 11
|
||||
A(2,5) = 13
|
||||
A(3,0) = 5
|
||||
A(3,1) = 13
|
||||
A(3,2) = 29
|
||||
A(3,3) = 61
|
||||
A(3,4) = 125
|
||||
A(3,5) = 253
|
||||
A(4,0) = 13
|
||||
29
Task/Ackermann-function/jq/ackermann-function-4.jq
Normal file
29
Task/Ackermann-function/jq/ackermann-function-4.jq
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
# input: [m,n, cache]
|
||||
# output [value, updatedCache]
|
||||
def ack:
|
||||
|
||||
# input: [value,cache]; output: [value, updatedCache]
|
||||
def cache(key): .[1] += { (key): .[0] };
|
||||
|
||||
def pow2: reduce range(0; .) as $i (1; .*2);
|
||||
|
||||
.[0] as $m | .[1] as $n | .[2] as $cache
|
||||
| if $m == 0 then [$n + 1, $cache]
|
||||
elif $m == 1 then [$n + 2, $cache]
|
||||
elif $m == 2 then [2 * $n + 3, $cache]
|
||||
elif $m == 3 then [8 * ($n|pow2) - 3, $cache]
|
||||
else
|
||||
(.[0:2]|tostring) as $key
|
||||
| $cache[$key] as $value
|
||||
| if $value then [$value, $cache]
|
||||
elif $n == 0 then
|
||||
([$m-1, 1, $cache] | ack)
|
||||
| cache($key)
|
||||
else
|
||||
([$m, $n-1, $cache ] | ack)
|
||||
| [$m-1, .[0], .[1]] | ack
|
||||
| cache($key)
|
||||
end
|
||||
end;
|
||||
|
||||
def A(m;n): [m,n,{}] | ack | .[0];
|
||||
1
Task/Ackermann-function/jq/ackermann-function-5.jq
Normal file
1
Task/Ackermann-function/jq/ackermann-function-5.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
A(4,1)
|
||||
1
Task/Ackermann-function/jq/ackermann-function-6.jq
Normal file
1
Task/Ackermann-function/jq/ackermann-function-6.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
65533
|
||||
Loading…
Add table
Add a link
Reference in a new issue