Problem 30. Sort a list of complex numbers based on far they are from the origin.
Solution Stats
Problem Comments
-
4 Comments
It is useful to mention sort in 'descending' order of distance from origin.
hey
great problem!!!!
nice
Solution Comments
-
1 Comment
Wow, I didn't think this would actually work.
-
3 Comments
Writing a solution whose size is so close to Leading solution is such a happy thing.
which leading solutions size is always 7 :S
I'm interested in the problem is, but due to the beginner, can't write a perfect solution.So if you can share your solution with me,I will be grateful to you!
-
1 Comment
Interesting. If you leave the 'ComparisonMethod','abs' it's still correct (size is 13).
Though, I believe this is the shortest, universally correct solution.
-
2 Comments
I keep receiving 'Matrix dimensions must agree' when using c(c==-d)... it seems to work fine in matlab, but not on here. Any ideas?
Note that "c(c==-d) = d" means that c and d must be same size or d is scalar. Moreover if d is not a scalar, then all "c==-d" must be true. This code seems to work in rare case, when one value is negative real number, and the rest are positive real numbers, but I have not tested it.
-
1 Comment
This is like the 'War & Peace' solution. I like it!
-
2 Comments
where is the problem here? it works on matlab
The function has to be named "complexSort".
-
1 Comment
Thanks for sharing
-
2 Comments
-
1 Comment
Simple and elegant, i like it
-
1 Comment
i keep learning new features...
Problem Recent Solvers5116
Suggested Problems
-
Find relatively common elements in matrix rows
1586 Solvers
-
Find common elements in matrix rows
2121 Solvers
-
Create matrix of replicated elements
363 Solvers
-
Create an n-by-n null matrix and fill with ones certain positions
485 Solvers
-
Side of an equilateral triangle
4937 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!