47 lines
674 B
PHP
47 lines
674 B
PHP
<?php
|
|
/**
|
|
* Triangle Tn = n*(n+1)/2
|
|
* Pentagonal Pn = n*(3n-1)/2
|
|
* Hexagonal Hn = n*(2n-1)
|
|
* T(285) = P(165) = H(143) = 40755
|
|
* Find next
|
|
*/
|
|
|
|
function Tn($n)
|
|
{
|
|
return $n*($n+1)/2;
|
|
}
|
|
|
|
function Pn($n)
|
|
{
|
|
return $n*(3*$n-1)/2;
|
|
}
|
|
|
|
function Hn($n)
|
|
{
|
|
return $n*(2*$n-1);
|
|
}
|
|
|
|
echo "Tn(285)=".Tn(285).PHP_EOL;
|
|
echo "Pn(165)=".Pn(165).PHP_EOL;
|
|
echo "Hn(143)=".Hn(143).PHP_EOL;
|
|
|
|
|
|
for($t = 285; $t < 100000; $t++)
|
|
{
|
|
$triangle[$t] = Tn($t);
|
|
}
|
|
|
|
for($p = 165; $p < 100000; $p++)
|
|
{
|
|
$pentagonal[$p] = Pn($p);
|
|
}
|
|
|
|
for($h = 143; $h < 100000; $h++)
|
|
{
|
|
$hexagonal[$h] = Hn($h);
|
|
}
|
|
|
|
$result = array_intersect($triangle, $pentagonal, $hexagonal);
|
|
|
|
print_r($result); |