Sudan function: Difference between revisions

Add CLU
(Add Draco)
(Add CLU)
Line 480:
F(1,3,3) = 35
</pre>
 
=={{header|CLU}}==
<syntaxhighlight lang="clu">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</syntaxhighlight>
{{out}}
<pre>sudan(0,x,y):
0 1 2 3 4 5 6
0: 0 1 2 3 4 5 6
1: 1 2 3 4 5 6 7
2: 2 3 4 5 6 7 8
3: 3 4 5 6 7 8 9
4: 4 5 6 7 8 9 10
5: 5 6 7 8 9 10 11
 
sudan(1,x,y):
0 1 2 3 4 5 6
0: 0 1 2 3 4 5 6
1: 1 3 5 7 9 11 13
2: 4 8 12 16 20 24 28
3: 11 19 27 35 43 51 59
4: 26 42 58 74 90 106 122
5: 57 89 121 153 185 217 249
 
sudan(1, 3, 3) = 35
sudan(2, 1, 1) = 8
sudan(2, 2, 1) = 27
sudan(3, 1, 1) = 10228</pre>
 
=={{header|Draco}}==
2,114

edits