Sudan function: Difference between revisions

no edit summary
m (Corrected an error in the function name.)
No edit summary
Line 797:
{{out}}
<pre>Same as C++ entry.</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
 
<syntaxhighlight lang="Delphi">
 
 
function SudanFunction(N,X,Y: integer): integer;
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(Memo: TMemo; N,X,Y: integer);
begin
Memo.Lines.Add(Format('Sudan(%d,%d,%d)=%d',[n,x,y,SudanFunction(N,X,Y)]));
end;
 
 
procedure ShowSudanFunctions(Memo: TMemo);
var N,X,Y: integer;
var S: string;
begin
for N:=0 to 1 do
begin
Memo.Lines.Add(Format('Sudan(%d,X,Y)',[N]));
Memo.Lines.Add('Y/X 0 1 2 3 4 5');
Memo.Lines.Add('----------------------------');
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;
Memo.Lines.Add(S);
end;
Memo.Lines.Add('');
end;
 
ShowSudanFunction(Memo, 1, 3, 3);
ShowSudanFunction(Memo, 2, 1, 1);
ShowSudanFunction(Memo, 2, 2, 1);
ShowSudanFunction(Memo, 3, 1, 1);
end;
 
 
 
 
</syntaxhighlight>
{{out}}
<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(3,1,1)=10228
 
Elapsed Time: 47.644 ms.
 
</pre>
 
 
=={{header|Draco}}==
465

edits