MathPHP\Sequence\Advanced::lazyCaterers PHP Méthode

lazyCaterers() public static méthode

https://en.wikipedia.org/wiki/Lazy_caterer%27s_sequence https://oeis.org/A000124 n² + n + 2 p = ---------- 2 Using binomial coefficients: (n + 1) (n) (n) (n) p = 1 + ( ) = ( ) + ( ) + ( ) ( 2 ) (0) (1) (2) Example: n = 6 Sequence: 1, 2, 4, 7, 11, 16, 22 Array index: 0, 1, 2, 3, 4, 5, 6
public static lazyCaterers ( integer $n ) : array
$n integer How many numbers in the sequence
Résultat array
    public static function lazyCaterers(int $n) : array
    {
        if ($n < 0) {
            return [];
        }
        $p = [];
        for ($i = 0; $i < $n; $i++) {
            $p[] = ($i ** 2 + $i + 2) / 2;
        }
        return $p;
    }