Sorting algorithms/Bogosort: Difference between revisions

Added Easylang
(→‎Insitux: implementation)
(Added Easylang)
 
(5 intermediate revisions by 4 users not shown)
Line 798:
}
}</syntaxhighlight>
 
=={{header|BASIC256}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang="vb">global array
dim array = {10, 1, 2, -6, 3}
lb = array[?,]-1 : ub = array[?]-1
 
print "unsort ";
for i = lb to ub
print rjust(array[i], 4);
next i
 
call Bogosort(array) # ordenar el array
 
print chr(10); " sort ";
for i = lb to ub
print rjust(array[i], 4);
next i
end
 
subroutine shuffle(array)
n = array[?] : m = array[?]*2
 
for k = 1 to m
i = int(Rand*n)
j = int(Rand*n)
tmp = array[i] #swap lb(i), lb(j)
array[i] = array[j]
array[j] = tmp
next k
end subroutine
 
function inorder(array)
n = array[?]
for i = 0 to n-2
if array[i] > array[i+1] then return false
next i
return true
end function
 
subroutine Bogosort(array)
while not inorder(array)
call shuffle(array)
end while
end subroutine</syntaxhighlight>
 
=={{header|BBC BASIC}}==
Line 1,140 ⟶ 1,185:
}
}</syntaxhighlight>
 
=={{header|EasyLang}}==
<syntaxhighlight>
proc shuffle . l[] .
for i = len l[] downto 2
r = randint i
swap l[i] l[r]
.
.
proc issorted . l[] r .
for i = 2 to len l[]
if l[i] < l[i - 1]
r = 0
return
.
.
r = 1
.
proc bogosort . l[] .
repeat
issorted l[] r
until r = 1
shuffle l[]
.
.
list[] = [ 2 7 41 11 3 1 6 5 8 ]
bogosort list[]
print list[]
</syntaxhighlight>
 
{{out}}
<pre>
[ 1 2 3 5 6 7 8 11 41 ]
</pre>
 
=={{header|Eiffel}}==
Line 1,647 ⟶ 1,726:
 
<syntaxhighlight lang="insitux">(function bogo-sort order list
(return-whenunless (empty?1 list) [])
(if (... order list)
list
(recur order (shuffle list))))
Line 3,016 ⟶ 3,095:
[0, 1, 2, 2, 4, 31, 65, 83, 99, 782]
</pre>
 
=={{header|RPL}}==
<code>KNUTH</code> is defined at [[Knuth shuffle#RPL|Knuth shuffle]]
{{works with|HP|48G}}
≪ '''WHILE''' DUP ΔLIST ≪ MIN ≫ STREAM 0 < '''REPEAT'''
<span style="color:blue">KNUTH</span>
'''END'''
≫ '<span style="color:blue">BOGOSORT</span>' STO
 
=={{header|Ruby}}==
Line 3,496 ⟶ 3,583:
=={{header|Wren}}==
{{libheader|Wren-sort}}
<syntaxhighlight lang="ecmascriptwren">import "random" for Random
import "./sort" for Sort
 
var bogoSort = Fn.new { |a|
Line 3,545 ⟶ 3,632:
=={{header|Yabasic}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang="yabasic">dim a(5)
a (0) = 10: a (1) = 1: a (2) = 2: a (3) = -6: a (4) = 3
 
Bogosort(a())
 
for i = 0 to arraysize(a(),1) - 1
print a(i), " ";
next i
end
 
sub shuffle(a())
n = arraysize(a(),1)
Line 3,563 ⟶ 3,659:
for i = 0 to n-2
if a(i) > a(i+1) then return false : fi
next i
return true
Line 3,572 ⟶ 3,668:
shuffle(a())
wend
end sub</syntaxhighlight>
 
dim a(5)
a (0) = 10: a (1) = 1: a (2) = 2: a (3) = -6: a (4) = 3
 
Bogosort(a())
 
for i = 0 to arraysize(a(),1) - 1
print a(i), " ";
next i
end
</syntaxhighlight>
 
 
=={{header|zkl}}==
1,978

edits