Guest User

Untitled

a guest
Jul 22nd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. <?php
  2. $array = array(5, 3, 2, 1, 7);
  3.  
  4.  
  5. function worse_recursive_ordering($array) {
  6. if (count($array) <= 1) {
  7. return $array;
  8. }
  9. // Find minimum
  10. $minimum = $array[0];
  11. foreach ($array as $i => $el) {
  12. if ($el < $minimum) {
  13. $minimum = $el;
  14. }
  15. }
  16. // The weird ordering happens here
  17. while ($array[0] != $minimum) shuffle($array);
  18. return array_merge(array($minimum), worse_recursive_ordering(array_slice($array, 1)));
  19. }
  20.  
  21. $result = worse_recursive_ordering($array);
  22. var_dump($result);
Add Comment
Please, Sign In to add comment