Created
March 9, 2015 13:54
-
-
Save wogsland/38550cdea2f34280ae43 to your computer and use it in GitHub Desktop.
Tantalizing Function
This file contains 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 | |
/* | |
t(p) = max {n: n mod k = 0 for all k such that k^p <=n} | |
From https://twitter.com/republicofmath/status/574618883111411713 | |
Basically, the question is, "is this function always finite?" | |
*/ | |
//print_r( $argv); | |
$p = $argv[1]; | |
$end = false; | |
$n = 1; | |
$set = array(); | |
while (!$end) { | |
$k = 1; | |
//echo 'k^p = '.(pow($k,$p))."\n"; | |
$divisible = true; | |
while (pow($k,$p) <= $n && $divisible) { | |
echo "testing n = $n & k = $k\n"; | |
if ($n % $k != 0) { | |
$divisible = false; | |
} | |
$k++; | |
} | |
if ($divisible) { | |
$set[] = $n; | |
if (isset($max)) { | |
$diff = $n - $max; | |
} else { | |
$diff = 1; | |
} | |
$max = $n; | |
} else { | |
$diff = 1; | |
} | |
if ($n > 3*$max) $end = true; | |
//$n++; | |
$n += $diff; | |
} | |
echo "p = $p\n"; | |
echo "n = $n\n"; | |
echo "k = $k\n"; | |
echo "set is\n"; | |
print_r($set); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment