Talk:Dutch national flag problem: Difference between revisions

Line 24:
 
::Hi, The Python is set up to generate a randomized, random sample of from one to five balls of each colour so it only has to check that the balls returned are not ordered. I don't read J code but I guess if you have the possibility of generating zero balls of a colour then the check would have to be for more? --[[User:Paddy3118|Paddy3118]] 06:29, 2 July 2012 (UTC)
 
:::Yes. (3||.@/:)^:(-:/:~)@:? first tries to generate values independently of each other, then it tests to see if they are sorted. If they are sorted, it generates a red,white,blue,red,white... sequence of the same length as the original sequence, and then reverses it. This "eliminate random values which are sorted" thing seems to be a dubious requirement though, for the test data -- as near as I can tell the main thing it accomplishes is allowing sort implementations which are broken when the data is already sorted. --[[User:Rdm|Rdm]] 13:28, 2 July 2012 (UTC)
6,962

edits