All numbers must add up to 15 . No number can be repeated more than once. Numbers are from 1-9.
What are the possible values for X?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
<?php
//build all 9 digit combinations (123456789 through 987654321)
$arr = range(1,9);
do{
$newarr = array();
foreach($arr as $a){
for($i=1;$i<=9;$i++){
if( !preg_match('@'.$i.'@',$a) ){
$newarr[] = $a.$i;
}
}
}
$arr = $newarr;
} while( strlen( $arr[0] ) < 9 );
//loop through the array, checking sum of each row/column/diagonal
foreach($arr as $a){
if($a[0]+$a[1]+$a[2]==15 && $a[0]+$a[3]+$a[6]==15 && $a[0]+$a[4]+$a[8]==15 && $a[1]+$a[4]+$a[7]==15 && $a[2]+$a[5]+$a[8]==15 && $a[3]+$a[4]+$a[5]==15 && $a[6]+$a[7]+$a[8]==15 && $a[2]+$a[4]+$a[6]==15){
echo $a.'<br>';
}
}
?>
The code above tells me that these are all of the possible ways to solve this puzzle, noting that every solution begins with an even number
276951438
294753618
438951276
492357816
618753294
672159834
816357492
834159672