Dutch national flag problem: Difference between revisions

m
 
(11 intermediate revisions by 5 users not shown)
Line 1,398:
</pre>
 
 
=={{header|FutureBasicEasyLang}}==
</syntaxhighlight>
col$[] = [ "red" "white" "blue" ]
for i to 8
b[] &= randint 3
.
for b in b[]
write col$[b] & " "
if b < b0
not_sorted = 1
.
b0 = b
.
print ""
print ""
if not_sorted = 0
print "already sorted"
else
for i = 01 to countlen b[] - 1
for j = i + 1 to len b[]
if b[j] < b[i]
swap b[j] b[i]
.
.
.
for b in b[]
write col$[b] & " "
.
.
</syntaxhighlight lang="furturebasic">
 
=={{header|Elixir}}==
Line 1,848 ⟶ 1,879:
End
</syntaxhighlight>
 
=={{header|FutureBasic}}==
FB has native sort functions ideal for this task.
<syntaxhighlight lang="furturebasic">
local fn SortBalls
CFArrayRef unsortedArray = @[@"🔴",@"⚪️",@"🔵",@"🔵",@"🔵",@"🔴",@"🔴",@"⚪️",@"⚪️",@"🔵",@"🔴",@"🔴",@"🔴",@"🔵",@"⚪️",@"🔴",@"🔴",@"🔵",@"⚪️"]
CFArrayRef sortedArray = fn ArraySortedArrayUsingSelector( unsortedArray, @"localizedStandardCompare:" )
NSUInteger i, index = 0, mark, count = len(sortedArray)
CFMutableArrayRef mutArr = fn MutableArrayWithArray( sortedArray )
for i = 0 to count - 1
if fn StringIsEqual( mutArr[i], mutArr[i+1] ) then index++ else exit for
next
CFArrayRef firstColorArray = fn ArraySubarrayWithRange( mutArr, fn CFRangeMake( 0, index + 1 ) )
CFStringRef firstColorString = fn ArrayComponentsJoinedByString( firstColorArray, @"" )
MutableArrayRemoveObjectsInRange( mutArr, fn CFRangeMake( 0, index + 1 ) )
count = len(mutArr) : index = 0
for i = 0 to count - 1
if fn StringIsEqual( mutArr[i], mutArr[i+1] ) then index++ else exit for
next
CFArrayRef secondColorArray = fn ArraySubarrayWithRange( mutArr, fn CFRangeMake( 0, index + 1 ) )
CFStringRef secondColorString = fn ArrayComponentsJoinedByString( secondColorArray, @"" )
MutableArrayRemoveObjectsInRange( mutArr, fn CFRangeMake( 0, index + 1 ) )
CFStringRef thirdColorString = fn ArrayComponentsJoinedByString( mutArr, @"" )
printf @"Unsorted balls:\n\t%@\n", fn ArrayComponentsJoinedByString( unsortedArray, @"" )
printf @"Sorted balls:\n\t%@", fn StringWithFormat( @"%@%@%@", secondColorString, firstColorString, thirdColorString )
end fn
 
fn SortBalls
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
Unsorted balls:
🔴⚪️🔵🔵🔵🔴🔴⚪️⚪️🔵🔴🔴🔴🔵⚪️🔴🔴🔵⚪️
 
Sorted balls:
🔴🔴🔴🔴🔴🔴🔴🔴⚪️⚪️⚪️⚪️⚪️🔵🔵🔵🔵🔵🔵
</pre>
 
=={{header|Gambas}}==
Line 3,944 ⟶ 3,935:
i = i + 1 ' fairly efficient exchange
j = j + 1
Else If @(j) = 2 thenThen ' case "blue"
Push @(j) : @(j) = @(k) : @(k) = Pop()
k = k - 1 ' fairly efficient exchange
Line 3,966 ⟶ 3,957:
 
0 OK, 0:858</pre>
 
=={{header|UNIX Shell}}==
{{works with|Bash}}
Line 4,174 ⟶ 4,166:
=={{header|Wren}}==
{{libheader|Wren-sort}}
<syntaxhighlight lang="ecmascriptwren">import "random" for Random
import "./sort" for Sort
 
var colors = ["Red", "White", "Blue"]
1,978

edits