Dutch national flag problem: Difference between revisions

(→‎sed: add)
Line 3,567:
<pre>Generated balls (Blue Blue Blue White Blue Blue Red Red Blue White) are not sorted.
Sorted balls (Red Red White White Blue Blue Blue Blue Blue Blue) are sorted.</pre>
 
=={{header|sed}}==
The first part of the task is skipped, as there is no possibility to create random data within ''sed'' itself.
<syntaxhighlight lang="sed">:la
s/\(WW*\)\([RB].*\)/\2\1/
t la
:lb
s/\(BB*\)\([RW].*\)/\2\1/
t lb
/^RR*WW*BB*$/!d</syntaxhighlight>
{{out}}
<pre>
$ echo WRRWRRRBBWBRRWBWWB | sed -f dutch_flag_sort.sed
RRRRRRRWWWWWWBBBBB
</pre>
 
=={{header|SQL}}==
559

edits