Beispiel #1
0
function q44()
{
    $pentagonalNumbers = [];
    $i = 0;
    while (true) {
        $pentagonalNumber = Number::pentagonal(++$i);
        $pentagonalNumbers[$pentagonalNumber] = $pentagonalNumber;
        foreach ($pentagonalNumbers as $firstPentagonalNumber) {
            $secondPentagonalNumber = $pentagonalNumber - $firstPentagonalNumber;
            if ($firstPentagonalNumber === $secondPentagonalNumber) {
                continue;
            }
            if (!isset($pentagonalNumbers[$secondPentagonalNumber])) {
                continue;
            }
            $difference = $secondPentagonalNumber - $firstPentagonalNumber;
            if (isset($pentagonalNumbers[$difference])) {
                return $secondPentagonalNumber - $firstPentagonalNumber;
            }
        }
    }
}
Beispiel #2
0
function q45($t, $p, $h)
{
    $px = Number::pentagonal($p);
    $tx = Number::triangle($t);
    while (true) {
        $hx = Number::hexagonal(++$h);
        $count = 1;
        while ($hx >= Number::pentagonal($p + 1)) {
            $px = Number::pentagonal(++$p);
        }
        if ($px === $hx) {
            ++$count;
        }
        while ($hx >= Number::triangle($t + 1)) {
            $tx = Number::triangle(++$t);
        }
        if ($tx === $hx) {
            ++$count;
        }
        if ($count === 3) {
            return $hx;
        }
    }
}