Created
September 18, 2020 16:00
-
-
Save llagerlof/fab77d3a0a2f9ab8ddf8c8d636314a0d to your computer and use it in GitHub Desktop.
PHP Automorphic Number Finder Algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| PHP Automorphic Number Finder Algorithm | |
| Author: Lawrence Lagerlof | |
| License: MIT | |
| */ | |
| $limit = 1000000; | |
| $milestone = $limit / 100; | |
| for ($n = 2; $n <= $limit; $n++) { | |
| $square = (string) $n * $n; | |
| $final = substr($square, strlen((string) $n) * (-1), strlen($square)); | |
| if ((string) $n == $final) { | |
| echo "\n" . 'number = ' . str_pad($n, strlen($square), ' ', STR_PAD_LEFT) . "\n"; | |
| echo 'squared = ' . $square . "\n\n"; | |
| } | |
| if (($n % $milestone) === 0) { | |
| echo ($n / $limit * 100) . " %\n"; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment