Menu

[r376]: / XACK.MPL  Maximize  Restore  History

Download this file

23 lines (17 with data), 433 Bytes

/*
  THE ACKERMANN FUNCTION - MPL VERSION
  BASED ON C# VERSION
  HTTP://ROSETTACODE.ORG/WIKI/ACKERMANN_FUNCTION
*/

##LIBHDR

.OK=1,2,3,4,5,2,3,4,5,6,3,5,7,9,11,5,13,29,61,125

ACK(M,N) ==M ? N+1 : ==N ? ACK(M-1,1) : ACK(M-1, ACK(M,N-1))

.(;I,N,M) [
  I=M=0; M<=3 @ [
    N=0; N<=4 @ [
      WRITEF("ACKERMANN(%N, %N) = %I3 (%S)*N",M,N,AUX=ACK(M,N),?(.OK!I++)?"TRUE":"FALSE");
      ++N
    ];
    ++M
  ]
]
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.