Skip to content

Instantly share code, notes, and snippets.

@johnciacia
Created May 28, 2011 00:44
Show Gist options
  • Save johnciacia/996463 to your computer and use it in GitHub Desktop.
Save johnciacia/996463 to your computer and use it in GitHub Desktop.
Bogosort
<?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