Created
May 28, 2011 00:44
-
-
Save johnciacia/996463 to your computer and use it in GitHub Desktop.
Bogosort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$a = array(3, 2, 1, 5, 9, 0, 7, 4, 6, 8); | |
while(!is_sorted($a)) | |
shuffle($a); | |
print_r($a); | |
function is_sorted($a) { | |
for($i = 0; $i < count($a); $i++) | |
if($a[$i] < $a[$i-1]) | |
return false; | |
return true; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment