Advertisement
puggan

9riddle.php v2

Dec 22nd, 2016
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.73 KB | None | 0 0
  1. <?php
  2. /** solving https://youtu.be/WiB2_dXSSMg */
  3. function reorder($a)
  4. {
  5.    if(count($a) <=1)
  6.    {
  7.       yield $a;
  8.    }
  9.    else
  10.    {
  11.       foreach($a as $k => $v)
  12.       {
  13.          $x = array($k => $v);
  14.          $b = $a;
  15.          unset($b[$k]);
  16.          foreach(reorder($b) as $c)
  17.          {
  18.             yield $c + $x;
  19.          }
  20.       }
  21.    }
  22. }
  23.  
  24. $n = range(1, 9);
  25.  
  26. foreach(reorder($n) as $cn)
  27. {
  28.    $a = array_values($cn);
  29.    $s = $a[0] +13*$a[1]/$a[2] +$a[3] +12*$a[4] -$a[5] -11 +$a[6]*$a[7]/$a[8] - 10;
  30.    /* if($s == 66) */
  31.    if($s > 65.999 AND $s < 66.001)
  32.    {
  33.       echo "{$a[0]} + 13x{$a[1]}/{$a[2]} + {$a[3]} + 12x{$a[4]} - {$a[5]}";
  34.       echo " - 11 + {$a[6]}x{$a[7]}/{$a[8]} - 10 = {$s}" . PHP_EOL;
  35.    }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement