Guest User

Untitled

a guest
Jan 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.73 KB | None | 0 0
  1. $x = true;
  2. $tries = 0;
  3. while($x):
  4.      
  5.     $numbers = array(1,2,3,4,5,6,7,8,9);
  6.     shuffle($numbers);
  7.     $matriz = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i');
  8.  
  9.     $num = 0;
  10.     foreach($matriz as $key => $value):
  11.         $new_matriz[$value] = $numbers[$num];
  12.         $$value = $numbers[$num];
  13.         $num = $num + 1;
  14.     endforeach;
  15.  
  16.     if( $a + $b + $c == 15 &&
  17.         $d + $e + $f == 15 &&
  18.         $g + $h + $i == 15 &&
  19.         $a + $d + $g == 15 &&
  20.         $b + $e + $h == 15 &&
  21.         $c + $f + $i == 15 &&
  22.         $a + $e + $i == 15 &&
  23.         $g + $e + $c == 15 ){
  24.  
  25.         echo "<br>".$a . $b . $c ."<br>";
  26.         echo $d . $e . $f ."<br>";
  27.         echo $g . $h . $i ."<br><br>";
  28.         echo 'Tentantivas: '.$tries."<br>";
  29.         $x = false;
  30.     }else{
  31.         $tries = $tries + 1 ;
  32.         $x = true;
  33.     }
  34. endwhile;
Add Comment
Please, Sign In to add comment