Order by pair comparisons: Difference between revisions
Content added Content deleted
Line 306: | Line 306: | ||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
This task uses [https://rosettacode.org/wiki/Factorial_base_numbers_indexing_permutations_of_a_collection#F.23 Factorial base numbers indexing permutations of a collection (F#)] |
|||
<lang fsharp> |
<lang fsharp> |
||
// Order by pair comparisons. Nigel Galloway: April 23rd., 2021 |
// Order by pair comparisons. Nigel Galloway: April 23rd., 2021 |
||
let clrs=let n=System.Random() in lN2p [|for g in 7..-1..2->n.Next(g)|] [|"Red";"Orange";"Yellow";"Green";"Blue";"Indigo";"Violet"|] |
|||
type colours= Violet |Red |Green |Indigo |Blue |Yellow |Orange |
|||
let |
let rec fG n g=printfn "Is %s less than %s" n g; match System.Console.ReadLine() with "Yes"-> -1|"No"->1 |_->printfn "Enter Yes or No"; fG n g |
||
⚫ | |||
let fN g=match g with "Violet"->Some(Violet) |"Red"->Some(Red) |"Green"->Some(Green) |"Indigo"->Some(Indigo) |"Blue"->Some(Blue) |"Yellow"->Some(Yellow) |"Orange"->Some(Orange) |_->None |
|||
⚫ | |||
</lang> |
</lang> |
||
{{out}} |
{{out}} |
||
Possible interaction: |
|||
Typical outputs: |
|||
<pre> |
<pre> |
||
Is Indigo less than Orange |
|||
Enter colours seperated by spaces |
|||
Yes |
|||
⚫ | |||
Is Blue less than Orange |
|||
Blue Red Yellow sorted to [|Red; Blue; Yellow|] using 3 comparisons |
|||
Yes |
|||
Is Blue less than Indigo |
|||
Enter colours seperated by spaces |
|||
No |
|||
Red Orange Yellow Green Blue Indigo Violet |
|||
Is Yellow less than Orange |
|||
⚫ | |||
Yes |
|||
Is Yellow less than Blue |
|||
No |
|||
Is Red less than Orange |
|||
Yes |
|||
⚫ | |||
Yes |
|||
Is Red less than Blue |
|||
Yes |
|||
Is Red less than Indigo |
|||
Yes |
|||
Is Green less than Orange |
|||
Yes |
|||
Is Green less than Yellow |
|||
Yes |
|||
Is Green less than Blue |
|||
Yes |
|||
Is Green less than Indigo |
|||
Yes |
|||
Is Green less than Red |
|||
No |
|||
Is Violet less than Orange |
|||
Yes |
|||
Is Violet less than Yellow |
|||
Yes |
|||
Is Violet less than Blue |
|||
Yes |
|||
Is Violet less than Indigo |
|||
Yes |
|||
Is Violet less than Green |
|||
Yes |
|||
Is Violet less than Red |
|||
Yes |
|||
⚫ | |||
</pre> |
</pre> |
||