Sudan function: Difference between revisions
Content added Content deleted
No edit summary |
(→{{header|OCaml}}: added =={{header|Pascal}}== trans Delphi tested SudanFunction( 2, 2, 2) =15,569,256,417) |
||
Line 1,389: | Line 1,389: | ||
- : int = 15569256417 |
- : int = 15569256417 |
||
</pre> |
</pre> |
||
=={{header|Pascal}}== |
|||
==={{header|Pascal}}=== |
|||
{{trans|Delphi}} |
|||
<syntaxhighlight lang="pascal"> |
|||
program Sudan; |
|||
//trans https://rosettacode.org/wiki/Sudan_function#Delphi |
|||
{$IFDEF FPC} {$MODE DELPHI} {$OPTIMIZATION ON,ALL}{$ENDIF} |
|||
{$IFDEF WINDOWS}{$APPTYPE CONSOLE}{$ENDIF} |
|||
uses |
|||
sysutils; |
|||
function SudanFunction(N,X,Y: UInt64): UInt64; |
|||
begin |
|||
if n = 0 then |
|||
Result:=X + Y |
|||
else |
|||
if y = 0 then |
|||
Result:=X |
|||
else |
|||
Result:=SudanFunction(N - 1, SudanFunction(N, X, Y - 1), SudanFunction(N, X, Y - 1) + Y); |
|||
end; |
|||
procedure ShowSudanFunction(N,X,Y: UInt64); |
|||
begin |
|||
writeln(Format('Sudan(%d,%d,%d)=%d',[n,x,y,SudanFunction(N,X,Y)])); |
|||
end; |
|||
procedure ShowSudanFunctions; |
|||
var |
|||
N,X,Y: UInt64; |
|||
S: string; |
|||
begin |
|||
for N:=0 to 1 do |
|||
begin |
|||
writeln(Format('Sudan(%d,X,Y)',[N])); |
|||
writeln('Y/X 0 1 2 3 4 5'); |
|||
writeln('----------------------------'); |
|||
for Y:=0 to 6 do |
|||
begin |
|||
S:=Format('%2d | ',[Y]); |
|||
for X:=0 to 5 do |
|||
begin |
|||
S:=S+Format('%3d ',[SudanFunction(N,X,Y)]); |
|||
end; |
|||
writeln(S); |
|||
end; |
|||
writeln(''); |
|||
end; |
|||
end; |
|||
BEGIN |
|||
ShowSudanFunctions; |
|||
ShowSudanFunction( 1, 3, 3); |
|||
ShowSudanFunction( 2, 1, 1); |
|||
ShowSudanFunction( 2, 2, 1); |
|||
ShowSudanFunction( 2, 1, 2); |
|||
ShowSudanFunction( 3, 1, 1); |
|||
ShowSudanFunction( 2, 2, 2); |
|||
END.</syntaxhighlight> |
|||
{{out|@TIO.RUN}}<pre> |
|||
Sudan(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 |
|||
Sudan(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 |
|||
Sudan(1,3,3)=35 |
|||
Sudan(2,1,1)=8 |
|||
Sudan(2,2,1)=27 |
|||
Sudan(2,1,2)=10228 |
|||
Sudan(3,1,1)=10228 |
|||
Sudan(2,2,2)=15569256417 |
|||
Real time: 3.822 s CPU share: 98.74 %</pre> |
|||
=={{header|Perl}}== |
=={{header|Perl}}== |