Dutch national flag problem: Difference between revisions
Content added Content deleted
(→{{header|Haskell}}: test case for huge list) |
(gp) |
||
Line 354: | Line 354: | ||
Anyways, we can test that they are indeed sorted properly: |
Anyways, we can test that they are indeed sorted properly: |
||
<lang J> assert@(-: /:~)&b2i /:~&.b2i BALLS</lang> |
<lang J> assert@(-: /:~)&b2i /:~&.b2i BALLS</lang> |
||
=={{header|PARI/GP}}== |
|||
A [[counting sort]] might be more appropriate here, but that would conceal the details of the sort. |
|||
<lang parigp>compare(a,b)={ |
|||
if (a==b, |
|||
0 |
|||
, |
|||
if(a=="red" || b=="blue", -1, 1) |
|||
) |
|||
}; |
|||
r(n)=vector(n,i,if(random(3),if(random(2),"red","white"),"blue")); |
|||
inorder(v)=for(i=2,#v,if(compare(v[i-1],v[i])>0,return(0)));1; |
|||
v=r(10); |
|||
while(inorder(v), v=r(10)); |
|||
v=vecsort(v,compare); |
|||
inorder(v)</lang> |
|||
Output: |
|||
<pre>1</pre> |
|||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |