Sorting algorithms/Bogosort: Difference between revisions

Content added Content deleted
No edit summary
Line 841:
END PROGRAM BOGOSORT</lang>
 
=={{header|Gambas}}==
'''[https://gambas-playground.proko.eu/?gist=b2b766f379d809cbf054c2d32d76c453 Click this link to run this code]'''
<lang gambas>Public Sub Main()
Dim sSorted As String = "123456789" 'The desired outcome
Dim sTest, sChr As String 'Various strings
Dim iCounter As Integer 'Loop counter
 
Do
Inc iCounter 'Increase counter value
Repeat 'Repeat
sChr = Chr(Rand(49, 57)) 'Get a random number and convert it to a character e.g. 49="1"
If Not InStr(sTest, sChr) Then sTest &= sChr 'If the random character is not in sTest then add it
Until Len(sTest) = 9 'Loop until sTest has 9 characters
Print sTest 'Print the string to test
If sTest = sSorted Then Break 'If sTest = sSorted then get out of the loop
sTest = "" 'Empty sTest and try again
Loop
 
Print "Solved in " & Str(iCounter) & " loops" 'Print the result
 
End</lang>
Output:
<pre>
.........
129536487
345218769
482713659
286745931
123456789
Solved in 155283 loops
</pre>
 
=={{header|Go}}==