RosettaCodeData/Task/Sudan-function/CLU/sudan-function.clu

44 lines
1.3 KiB
Plaintext

sudan = proc (n, x, y: int) returns (int)
if n=0 then
return(x + y)
elseif y=0 then
return(x)
else
k: int := sudan(n, x, y-1)
return(sudan(n-1, k, k+y))
end
end sudan
table = proc (n, xs, ys: int) returns (string)
ss: stream := stream$create_output()
stream$putl(ss, "sudan(" || int$unparse(n) || ",x,y):")
stream$puts(ss, " ")
for x: int in int$from_to(0, xs)
do stream$putright(ss, int$unparse(x), 5) end
for y: int in int$from_to(0, ys) do
stream$putl(ss, "")
stream$putright(ss, int$unparse(y) || ":", 5)
for x: int in int$from_to(0, xs)
do stream$putright(ss, int$unparse(sudan(n, x, y)), 5) end
end
stream$putl(ss, "")
return(stream$get_contents(ss))
end table
show = proc (n, x, y: int) returns (string)
return("sudan(" || int$unparse(n)
|| ", " || int$unparse(x)
|| ", " || int$unparse(y)
|| ") = " || int$unparse(sudan(n,x,y)))
end show
start_up = proc ()
po: stream := stream$primary_output()
stream$putl(po, table(0, 6, 5))
stream$putl(po, table(1, 6, 5))
stream$putl(po, show(1, 3, 3))
stream$putl(po, show(2, 1, 1))
stream$putl(po, show(2, 2, 1))
stream$putl(po, show(3, 1, 1))
end start_up