Skip to content

Instantly share code, notes, and snippets.

@wogsland
Created March 9, 2015 13:54
Show Gist options
  • Save wogsland/38550cdea2f34280ae43 to your computer and use it in GitHub Desktop.
Save wogsland/38550cdea2f34280ae43 to your computer and use it in GitHub Desktop.
Tantalizing Function
<?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