Sudan function: Difference between revisions
Content added Content deleted
(Ada version) |
(Added Algol 68) |
||
Line 50: | Line 50: | ||
F2 (2, 1) = 27 |
F2 (2, 1) = 27 |
||
F3 (1, 1) = 10228 |
F3 (1, 1) = 10228 |
||
</pre> |
|||
=={{header|ALGOL 68}}== |
|||
{{Trans|Wren}} |
|||
...with a minor optimisation. |
|||
<lang algol68>BEGIN # compute some values of the Sudan function # |
|||
PROC sudan = ( INT n, x, y )INT: |
|||
IF n = 0 THEN x + y |
|||
ELIF y = 0 THEN x |
|||
ELSE |
|||
INT s = sudan( n, x, y - 1 ); |
|||
sudan( n - 1, s, s + y ) |
|||
FI # sudan # ; |
|||
FOR n FROM 0 TO 1 DO |
|||
print( ( "Values of F(", whole( n, 0 ), ", x, y):", newline ) ); |
|||
print( ( "y/x 0 1 2 3 4 5", newline ) ); |
|||
print( ( "----------------------------", newline ) ); |
|||
FOR y FROM 0 TO 6 DO |
|||
print( ( whole( y, 0 ), " |" ) ); |
|||
FOR x FROM 0 TO 5 DO |
|||
print( ( whole( sudan( n, x, y ), -4 ) ) ) |
|||
OD; |
|||
print( ( newline ) ) |
|||
OD; |
|||
print( ( newline ) ) |
|||
OD; |
|||
print( ( newline ) ); |
|||
print( ( "F(2, 1, 1) = ", whole( sudan( 2, 1, 1 ), 0 ), newline ) ); |
|||
print( ( "F(3, 1, 1) = ", whole( sudan( 3, 1, 1 ), 0 ), newline ) ); |
|||
print( ( "F(2, 2, 1) = ", whole( sudan( 2, 2, 1 ), 0 ), newline ) ) |
|||
END</lang> |
|||
{{out}} |
|||
<pre> |
|||
Values of F(0, x, y): |
|||
y/x 0 1 2 3 4 5 |
|||
---------------------------- |
|||
0 | 0 1 2 3 4 5 |
|||
1 | 1 2 3 4 5 6 |
|||
2 | 2 3 4 5 6 7 |
|||
3 | 3 4 5 6 7 8 |
|||
4 | 4 5 6 7 8 9 |
|||
5 | 5 6 7 8 9 10 |
|||
6 | 6 7 8 9 10 11 |
|||
Values of F(1, x, y): |
|||
y/x 0 1 2 3 4 5 |
|||
---------------------------- |
|||
0 | 0 1 2 3 4 5 |
|||
1 | 1 3 5 7 9 11 |
|||
2 | 4 8 12 16 20 24 |
|||
3 | 11 19 27 35 43 51 |
|||
4 | 26 42 58 74 90 106 |
|||
5 | 57 89 121 153 185 217 |
|||
6 | 120 184 248 312 376 440 |
|||
F(2, 1, 1) = 8 |
|||
F(3, 1, 1) = 10228 |
|||
F(2, 2, 1) = 27 |
|||
</pre> |
</pre> |
||