Hello! I'm new (how often do you here that?) in the PHP world. I found a "simple" little brain teaser I thought I could program to test some of my newly acquired skills instead of using the old calculator. The object of it is to find two whole numbers (each less than 10) such that the sum of their squares, added to their product, will make a square. If a number pair is found, the program should display it.
Here's the code I've produced:
<?php
$Number1=1;
$Number1=(integer)$Number1;
for ($Number1; $Number1<10; $Number1++) {
echo "~~~~~~~~~~<br>";
echo "~~~~~~~~~~<br>";
echo "Number1 = $Number1 / ";
$Number2=1;
$Number2=(integer)$Number2;
for ($Number2; $Number2<10; $Number2++) {
echo "Number2 = $Number2<br>";
echo "------------------------<br>";
$TN1=pow($Number1,2);
echo "(Number1)2 = $TN1<br>";
$TN2=pow($Number2,2);
echo "(Number2)2 = $TN2<br>";
$Total1=($TN1 + $TN2) + ($Number1$Number2);
echo "(Number1)2 + (Number2)2 + (Number1 Number2) = $Total1<br>";
$Total2=sqrt($Total1);
echo "Square root = $Total2<br><br>";
if (is_int($Total2)) {
echo "The numbers are $Number1 and $Number2.<br><br>";
}
else {
echo "This pair doesn't fit the criteria of the test.<br>";
echo "^^^^^^^^^^^^^^^^^^^^^^^^^^<br><br>";
}
}
}
?>
It's simple-looking on the screen, but I programmed it specifically that way to "follow the trail" as it was developed. The actual answer involves two pairs: 3 & 5 and 7 & 8. My program works well up to the point of testing whether or not the square root of the final total is an integer, and I believe the answer lies with the use of 'is_int()'. So far, all of the documentation I've read (books and online) only talks about it with relation to user input fields in forms. Can someone help? Thanks for your patience!