ackermann.pp 434 B

12345678910111213141516171819202122
  1. program ackerman;
  2. {$mode objfpc}
  3. uses SysUtils;
  4. function Ack(const M, N : integer) : integer;
  5. begin
  6. if M = 0 then Ack := N+1
  7. else if N = 0 then Ack := Ack(M-1, 1)
  8. else Ack := Ack(M-1, Ack(M, N-1));
  9. end;
  10. var NUM, a: integer;
  11. begin
  12. if ParamCount = 0 then NUM := 1
  13. else NUM := StrToInt(ParamStr(1));
  14. if NUM < 1 then NUM := 1;
  15. a := Ack(3, NUM);
  16. WriteLn( 'Ack(3,' + IntToStr(NUM) + '): ' + IntToStr(a) );
  17. end.