Skip to content

Instantly share code, notes, and snippets.

@llagerlof
Created September 18, 2020 16:00
Show Gist options
  • Select an option

  • Save llagerlof/fab77d3a0a2f9ab8ddf8c8d636314a0d to your computer and use it in GitHub Desktop.

Select an option

Save llagerlof/fab77d3a0a2f9ab8ddf8c8d636314a0d to your computer and use it in GitHub Desktop.
PHP Automorphic Number Finder Algorithm
<?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