<?php

function Pn($n)
{
    return $n * (3 * $n - 1) / 2;
}

$pn = [];
for ($i = 1; $i < 2500; $i++) {
    $pn[] = (int) Pn($i);
}
$smallest_diff = PHP_INT_MAX;
echo "Precalculate done\n";
for ($ij = 0; $ij < sizeof($pn); $ij++) {
    echo "$ij%\n";
    $j = $pn[$ij];
    for ($ik = $ij + 1; $ik < sizeof($pn); $ik++) {
        $k = $pn[$ik];
        $sum = $j + $k;
        if (in_array($sum, $pn)) {
            $diff = (int) abs($k - $j);
            if (in_array($diff, $pn, true)) {
                if ($diff < $smallest_diff) {
                    $smallest_diff = $diff;
                    echo "Found: Pn($ij)=$j Pn($ik)=$k Sum: $sum Diff: $diff\n";
                }
            }
        }
    }
}

echo "Smallest diff: $smallest_diff";