Link.FYI

Pastebin

Create New My Pastes

Code (PHP (brief)) pasted on 2024-10-06, 17:39 Raw Source

  1.  <?php
  2. $result= [];
  3.    
  4.     $rangeLeft = $rangeRight = $p = "";
  5.     $c = count($depotData);
  6.     $mp = 10 - ($c -1);
  7.     $li = 1;
  8.     $ri = (10 - $c) + 1;
  9.     for($i=1; $i<=$c; $i++){
  10.         $rangeLeft .= $li;
  11.         $rangeRight .= $ri;
  12.     }
  13.     for($i=9;$i>=$mp;$i--){
  14.         $p.=$i;
  15.     }
  16.     $array=range($rangeLeft, $rangeRight); // Make an array with every number between e.g. 1117 and 7777
  17.     foreach ($array as $k => $v) {
  18.         if ((preg_match('/['.$p.'0]/',$v) === 0) && (array_sum(str_split($v, 1)) === 10)) {
  19.             // If number does not contain 8,9 or 0 and sum of all 4 numbers is 10
  20.             // Apply function to multiply each number by 10 and add to result array
  21.             $result[] = array_map("magnitude", str_split($v, 1));
  22.         }
  23.     }