Given an input vector of positive integers, return a row vector with the primes first (in increasing order) and the composites next (also in increasing order).
The number 1 is neither prime nor composite. Put it with the composites for this problem.
Solution Stats
Problem Comments
4 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers241
Suggested Problems
-
Least common multiple of many numbers
256 Solvers
-
Similar Triangles - find the height of the tree
479 Solvers
-
"Low : High - Low : High - Turn around " -- Create a subindices vector
592 Solvers
-
Find the index of the largest value in any vector X=[4,3,4,5,9,12,0,4.....5]
406 Solvers
-
Matlab Basics - y as a function of x
533 Solvers
More from this Author23
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
need to add non-sorted test samples (e.g. [3,2,1])?
It looks like 1 is being incorrectly sorted as a composite number in the testcases.
I somehow Alfonso's older comment until I saw Tom's newer one.
Alfonso: I've added a non-sorted test sample, and had the problem rescored.
Tom: 1 is neither prime nor composite. I've added instructions on how to handle that.
I had assumed that "in order" meant "in the order provided". If that were the case, then [5 1 3 2 4] would return [5 3 2 1 4]. Maybe you could say you want them sorted rather than in order.