Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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);
Add Comment
Please, Sign In to add comment