Skip to content

Instantly share code, notes, and snippets.

@flevour
Created February 11, 2011 20:56
Show Gist options
  • Save flevour/823014 to your computer and use it in GitHub Desktop.
Save flevour/823014 to your computer and use it in GitHub Desktop.
Making a worse ordering algo
<?php
$array = array(5, 3, 2, 1, 7);
function worse_recursive_ordering($array) {
if (count($array) <= 1) {
return $array;
}
// Find minimum
$minimum = $array[0];
foreach ($array as $i => $el) {
if ($el < $minimum) {
$minimum = $el;
}
}
// The weird ordering happens here
while ($array[0] != $minimum) shuffle($array);
return array_merge(array($minimum), worse_recursive_ordering(array_slice($array, 1)));
}
$result = worse_recursive_ordering($array);
var_dump($result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment