Sudan function: Difference between revisions
Content added Content deleted
Not a robot (talk | contribs) (Add BQN) |
Not a robot (talk | contribs) (Add Draco) |
||
Line 480: | Line 480: | ||
F(1,3,3) = 35 |
F(1,3,3) = 35 |
||
</pre> |
</pre> |
||
=={{header|Draco}}== |
|||
<syntaxhighlight lang="draco">proc sudan(word n, x, y) word: |
|||
word k; |
|||
if n=0 then |
|||
x + y |
|||
elif y=0 then |
|||
x |
|||
else |
|||
k := sudan(n, x, y-1); |
|||
sudan(n-1, k, k+y) |
|||
fi |
|||
corp |
|||
proc table(word n, xs, ys) void: |
|||
word x, y; |
|||
writeln("sudan(",n,",x,y):"); |
|||
write(" "); |
|||
for x from 0 upto xs do write(x:5) od; |
|||
for y from 0 upto ys do |
|||
writeln(); |
|||
write(y:4, ":"); |
|||
for x from 0 upto xs do write(sudan(n,x,y):5) od; |
|||
od; |
|||
writeln(); |
|||
writeln() |
|||
corp |
|||
proc show(word n, x, y) void: |
|||
writeln("sudan(", n:1, ",", x:3, ",", y:3, ") = ", sudan(n,x,y):5) |
|||
corp |
|||
proc main() void: |
|||
table(0, 6, 5); |
|||
table(1, 6, 5); |
|||
show(1, 3, 3); |
|||
show(2, 1, 1); |
|||
show(2, 2, 1); |
|||
show(3, 1, 1) |
|||
corp</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|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
Line 496: | Line 559: | ||
15569256417 |
15569256417 |
||
</pre> |
</pre> |
||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
{{works with|Factor|0.99 2022-04-03}} |
{{works with|Factor|0.99 2022-04-03}} |