/*
// a number "n" is automorphic if n^2 ends with "n"
e.g. 5 is automorphic number, because 5^2=25 ends with 5, 6^2=36 and is automorphic as well;
*/

echo "5 - ".isAutomorphic_2(5)."\n";    // 25
echo "8 - ".isAutomorphic_2(8)."\n";    // 64
echo "76 - ".isAutomorphic_2(76)."\n";  // 5,776

function isAutomorphic($num){
	$square=$num*$num;
	
	$result=str_ends_with($square, $num);
	return $result;
}


//using substring function
function isAutomorphic_2($num){
	return substr($num*$num, -1*strlen($num)) === strval($num);
}
by ვაჟა ტყემალაძე
2 years ago
PHP
Problem Solving
php
Note
Problem
0
Pro tip: use ```triple backticks around text``` to write in code fences