Cody

# Problem 42639. Find the Final State of an Abelian Sandpile

Solution 2215691

Submitted on 17 Apr 2020
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   Fail
A = 1; B_correct = 1; assert(isequal(sandpile(A),B_correct))

Output argument "B" (and maybe others) not assigned during call to "sandpile". Error in Test1 (line 3) assert(isequal(sandpile(A),B_correct))

2   Fail
A = [0 0 0;0 4 1;1 0 0]; B_correct = [0 1 0;1 0 2;1 1 0]; assert(isequal(sandpile(A),B_correct))

Index in position 2 is invalid. Array indices must be positive integers or logical values. Error in sandpile (line 5) if A(i,j)>=4 Error in Test2 (line 3) assert(isequal(sandpile(A),B_correct))

3   Fail
A = [0 0 0 0;0 4 4 0;0 0 0 0]; B_correct = [0 1 1 0;1 1 1 1;0 1 1 0]; assert(isequal(sandpile(A),B_correct))

Index in position 2 is invalid. Array indices must be positive integers or logical values. Error in sandpile (line 5) if A(i,j)>=4 Error in Test3 (line 3) assert(isequal(sandpile(A),B_correct))

4   Fail
A = [0 0 0 0 0;0 0 0 0 0;0 0 17 0 0;0 0 0 7 0;0 0 0 0 0]; B_correct = [0 0 1 0 0;0 2 1 2 0;1 1 1 3 1;0 2 3 1 2;0 0 1 2 0]; assert(isequal(sandpile(A),B_correct))

Index in position 2 is invalid. Array indices must be positive integers or logical values. Error in sandpile (line 5) if A(i,j)>=4 Error in Test4 (line 3) assert(isequal(sandpile(A),B_correct))

5   Fail
A = [0 0 0 0 0 0 0 0 0 0 0;0 0 0 0 0 0 0 0 0 0 0;0 0 0 0 0 0 0 0 0 0 0;0 0 0 16 2 3 13 0 0 0 0;0 0 0 5 11 10 8 0 0 0 0;0 0 0 9 7 6 12 0 0 0 0;0 0 0 4 14 15 1 0 0 0 0;0 0 0 0 0 0 0 0 0 0 0;0 0 0 0 0 0 0 0 0 0 0;0 0 0 0 0 0 0 0 0 0 0;0 0 0 0 0 0 0 0 0 0 0]; B_correct = [0 0 0 0 0 0 0 0 0 0 0;0 0 1 3 3 3 3 1 0 0 0;0 2 3 2 3 3 2 3 2 0 0;1 1 1 3 2 3 1 1 1 1 0;1 3 1 1 3 3 1 2 3 1 0;1 3 0 3 3 3 3 1 3 1 0;1 0 3 2 2 3 0 3 0 1 0;0 2 2 3 2 2 3 2 2 0 0;0 0 2 0 3 3 0 2 0 0 0;0 0 0 1 1 1 1 0 0 0 0;0 0 0 0 0 0 0 0 0 0 0]; assert(isequal(sandpile(A),B_correct))

Index in position 2 is invalid. Array indices must be positive integers or logical values. Error in sandpile (line 5) if A(i,j)>=4 Error in Test5 (line 3) assert(isequal(sandpile(A),B_correct))