Jump to content

Order by pair comparisons: Difference between revisions

Added Quackery.
(added ocaml with sort)
(Added Quackery.)
Line 889:
 
red orange yellow green blue indigo violet</pre>
 
=={{header|Quackery}}==
 
<code>sortwith</code> sorts by insertion sort by default, of by merge sort falling back to insertion sort for nests of fewer than 16 items if the Quackery extensions are loaded. In either instance, as this is sorting a nest of seven items, it will be by insertion sort.
 
<lang Quackery> [ $ "Is " swap join
$ " before " join
swap join
$ "? (y/n) " join
input $ "y" = ] is askuser
 
$ "red orange yellow green blue indigo violet"
say "Correct order --> "
dup echo$ cr cr
nest$ shuffle
dup witheach [ echo$ sp ] cr cr
sortwith askuser cr
witheach [ echo$ sp ] cr</lang>
 
{{out}}
 
<pre>Correct order --> red orange yellow green blue indigo violet
 
green blue orange indigo yellow violet red
 
Is blue before green? (y/n) n
Is orange before green? (y/n) y
Is indigo before orange? (y/n) n
Is indigo before green? (y/n) n
Is indigo before blue? (y/n) n
Is yellow before orange? (y/n) n
Is yellow before green? (y/n) y
Is violet before orange? (y/n) n
Is violet before yellow? (y/n) n
Is violet before green? (y/n) n
Is violet before blue? (y/n) n
Is violet before indigo? (y/n) n
Is red before orange? (y/n) y
 
red orange yellow green blue indigo violet
</pre>
 
=={{header|Raku}}==
1,462

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.