Cody

Problem 734. Ackermann's Function

Solution 1258999

Submitted on 29 Aug 2017 by Andy Seeder
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
m=0; n=1; Ack = n+1; assert(isequal(ackermann(m,n),Ack))

ans = 2 3 5 13 65533 ans = 2

2   Pass
m=0; n=1024; Ack = n+1; assert(isequal(ackermann(m,n),Ack))

ans = 1025 1026 2051 Inf 67092493 ans = 1025

3   Pass
m=0; n=randi(1024) Ack = n+1; assert(isequal(ackermann(m,n),Ack))

n = 510 ans = 1.0e+154 * 0.0000 0.0000 0.0000 2.6816 0.0000 ans = 511

4   Pass
m=1; n=1024 Ack = n+2; assert(isequal(ackermann(m,n),Ack))

n = 1024 ans = 1025 1026 2051 Inf 67092493 ans = 1026

5   Pass
m=1; n=randi(1024) Ack = n+2; assert(isequal(ackermann(m,n),Ack))

n = 812 ans = 1.0e+245 * 0.0000 0.0000 0.0000 2.1850 0.0000 ans = 814

6   Pass
m=2; n=randi(128) Ack = 2*n+3; assert(isequal(ackermann(m,n),Ack))

n = 14 ans = 15 16 31 131069 917293 ans = 31

7   Pass
m=3; n=6; Ack = 509; assert(isequal(ackermann(m,n),Ack))

ans = 7 8 15 509 393133 ans = 509

8   Pass
m=3; n=randi(6) Ack = 2^(n+3)-3; assert(isequal(ackermann(m,n),Ack))

n = 2 ans = 3 4 7 29 131053 ans = 29

9   Pass
m=4; n=0; Ack = 13; assert(isequal(ackermann(m,n),Ack))

ans = 1 2 3 5 13 ans = 13

10   Pass
m=4; n=1; % Fails at RecursionLimit 1030; Create Special Ack = 65533; assert(isequal(ackermann(m,n),Ack))

ans = 2 3 5 13 65533 ans = 65533

Suggested Problems

More from this Author241

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!