Advertisement
thornik

Bench 'Ackerman' for D

Dec 5th, 2017
2,175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.34 KB | None | 0 0
  1. // ldc2.exe -release -m64 -O ackermann.d
  2.  
  3. import std.stdio;
  4. import std.conv;
  5.  
  6. int Ack(int M, int N)
  7. {
  8.     if (M == 0) return N + 1;
  9.     if (N == 0) return Ack(M - 1, 1);
  10.     return Ack(M - 1, Ack(M, (N - 1)));
  11. }
  12.  
  13. void main(string[] args)
  14. {
  15.    int n = args.length < 2 ? 1 : to!int(args[1]);
  16.    writefln(`Ack(3, %s): %s`, n, Ack(3, n));
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement