Order by pair comparisons: Difference between revisions

Added AutoHotkey
(Order by pair comparisons en FreeBASIC)
(Added AutoHotkey)
Line 66:
 
sorted => [indigo orange yellow green blue red violet]</pre>
 
=={{header|AutoHotkey}}==
<lang AutoHotkey>data := ["Violet", "Red", "Green", "Indigo", "Blue", "Yellow", "Orange"]
result := [], num := 0, Questions :=""
 
for i, Color1 in data{
found :=false
if !result.count(){
result.Push(Color1)
continue
}
for j, Color2 in result {
if (color1 = color2)
continue
MsgBox, 262180,, % (Q := "Q" ++num " is " Color1 " > " Color2 "?")
ifMsgBox, Yes
Questions .= Q "`t`tYES`n"
else {
Questions .= Q "`t`tNO`n"
result.InsertAt(j, Color1)
found := true
break
}
}
if !found
result.Push(Color1)
}
for i, color in result
output .= color ", "
MsgBox % Questions "`nSorted Output :`n" Trim(output, ", ")
return</lang>
 
{{out}}
<pre>Q1 is Red > Violet? NO
Q2 is Green > Red? YES
Q3 is Green > Violet? NO
Q4 is Indigo > Red? YES
Q5 is Indigo > Green? YES
Q6 is Indigo > Violet? NO
Q7 is Blue > Red? YES
Q8 is Blue > Green? YES
Q9 is Blue > Indigo? NO
Q10 is Yellow > Red? YES
Q11 is Yellow > Green? NO
Q12 is Orange > Red? YES
Q13 is Orange > Yellow? NO
 
Sorted Output :
Red, Orange, Yellow, Green, Blue, Indigo, Violet</pre>
 
=={{header|C}}==
299

edits