03.07.2014, 13:04
This is a deeply recursive function:
Documentation:
http://en.wikipedia.org/wiki/Ackermann_function
Test script:
Don't do "ack(4, 1)"
ouch!
Tested at http://slice-vps.nl:7070/
pawn Код:
stock ack(m, n) {return (m == 0)?(n+1):((n == 0)?ack(m-1, 1):ack(m-1, ack(m, n-1)));}
http://en.wikipedia.org/wiki/Ackermann_function
Test script:
pawn Код:
#include <a_samp>
stock ack(m, n) {return (m == 0)?(n+1):((n == 0)?ack(m-1, 1):ack(m-1, ack(m, n-1)));}
main()
{
for(new i = 0; i < 5; i++) for(new j = 0; j < 5; j++) printf("ack(%d, %d) equals %d.", i, j, ack(i, j));
}
Код:
ack(0, 0) equals 1. ack(0, 1) equals 2. ack(0, 2) equals 3. ack(0, 3) equals 4. ack(0, 4) equals 5. ack(1, 0) equals 2. ack(1, 1) equals 3. ack(1, 2) equals 4. ack(1, 3) equals 5. ack(1, 4) equals 6. ack(2, 0) equals 3. ack(2, 1) equals 5. ack(2, 2) equals 7. ack(2, 3) equals 9. ack(2, 4) equals 11. ack(3, 0) equals 5. ack(3, 1) equals 13. ack(3, 2) equals 29. ack(3, 3) equals 61. ack(3, 4) equals 125. ack(4, 0) equals 13. [debug] Run time error 3: "Stack/heap collision (insufficient stack size)"
Tested at http://slice-vps.nl:7070/