summaryrefslogtreecommitdiff
path: root/fpcsrc/tests/bench/shootout/obsolete/ackermann.pp
blob: ca20cd44dfcc9f05bd55b59a10ea0293a6a147fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
program ackerman;

{$mode objfpc}

uses SysUtils;

function Ack(const M, N : integer) : integer;
begin
  if M = 0 then Ack := N+1
    else if N = 0 then Ack := Ack(M-1, 1)
      else Ack := Ack(M-1, Ack(M, N-1));
end;

var NUM, a: integer;
begin
  if ParamCount = 0 then NUM := 1
    else NUM := StrToInt(ParamStr(1));
  if NUM < 1 then NUM := 1;

  a := Ack(3, NUM);
  WriteLn( 'Ack(3,' + IntToStr(NUM) + '): ' + IntToStr(a) );
end.