Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.76 KB | None | 0 0
  1. <?php
  2.  
  3. $start = microtime(true);
  4.  
  5. function permutation($warehouses)
  6. {
  7.     if (array_search(null, $warehouses) !== false) {
  8.         for ($i = 0; $i < count($warehouses); $i++) {
  9.             if (!$warehouses[$i]) {
  10.                 $warehouses[$i] = count(array_filter($warehouses)) + 1;
  11.                 permutation($warehouses);
  12.                 $warehouses[$i] = null;
  13.             }
  14.         }
  15.     } else {
  16. //        foreach ($warehouses as $warehouse) {
  17. //            if ($warehouse) {
  18. //                echo $warehouse . ' ';
  19. //            }
  20. //        }
  21. //        echo PHP_EOL;
  22.     }
  23. }
  24.  
  25. $warehouses = array_fill(0, 9, null);
  26.  
  27. permutation($warehouses);
  28.  
  29. echo (microtime(true) - $start) / 60 . PHP_EOL;
  30. echo memory_get_peak_usage(true) / 1014 . PHP_EOL;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement