Cody

# Problem 30. Sort a list of complex numbers based on far they are from the origin.

Solution 895682

Submitted on 26 May 2016 by Dennis Winston
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
j = sqrt(-1); z = [-4 6 3+4*j 1+j 0]; zSorted_correct = [6 3+4*j -4 1+j 0]; assert(isequal(complexSort(z),zSorted_correct))

Z = 4.0000 6.0000 5.0000 1.4142 0 row = 1 col = 5 M = 6 p = 2 Z = 4.0000 0 5.0000 1.4142 0 M = 5 p = 2 3 Z = 4.0000 0 0 1.4142 0 M = 4 p = 2 3 1 Z = 0 0 0 1.4142 0 M = 1.4142 p = 2 3 1 4 Z = 0 0 0 0 0 M = 0 p = 2 3 1 4 1 Z = 0 0 0 0 0 p = 2 3 1 4 5 zSorted = 6.0000 + 0.0000i 3.0000 + 4.0000i -4.0000 + 0.0000i 1.0000 + 1.0000i 0.0000 + 0.0000i

2   Pass
z = 1:10; zSorted_correct = 10:-1:1; assert(isequal(complexSort(z),zSorted_correct))

Z = 1 2 3 4 5 6 7 8 9 10 row = 1 col = 10 M = 10 p = 10 Z = 1 2 3 4 5 6 7 8 9 0 M = 9 p = 10 9 Z = 1 2 3 4 5 6 7 8 0 0 M = 8 p = 10 9 8 Z = 1 2 3 4 5 6 7 0 0 0 M = 7 p = 10 9 8 7 Z = 1 2 3 4 5 6 0 0 0 0 M = 6 p = 10 9 8 7 6 Z = 1 2 3 4 5 0 0 0 0 0 M = 5 p = 10 9 8 7 6 5 Z = 1 2 3 4 0 0 0 0 0 0 M = 4 p = 10 9 8 7 6 5 4 Z = 1 2 3 0 0 0 0 0 0 0 M = 3 p = 10 9 8 7 6 5 4 3 Z = 1 2 0 0 0 0 0 0 0 0 M = 2 p = 10 9 8 7 6 5 4 3 2 Z = 1 0 0 0 0 0 0 0 0 0 M = 1 p = 10 9 8 7 6 5 4 3 2 1 Z = 0 0 0 0 0 0 0 0 0 0 p = 10 9 8 7 6 5 4 3 2 1 zSorted = 10 9 8 7 6 5 4 3 2 1