MathPHP\Sequence\Advanced::pentagonalNumber PHP Метод

pentagonalNumber() публичный статический Метод

https://en.wikipedia.org/wiki/Pentagonal_number 3n² - n pn = ------- 2 Example: n = 6 Sequence: 1, 5, 12, 22, 35, 51 Array index: 1, 2, 3, 4, 5, 6
public static pentagonalNumber ( integer $n ) : array
$n integer How many numbers in the sequence
Результат array Indexed from 1
    public static function pentagonalNumber(int $n) : array
    {
        $pentagonal = [];
        // Bad input; return empty list
        if ($n <= 0) {
            return $pentagonal;
        }
        // Standard case for pn: (3n² - n) / 2
        for ($i = 1; $i <= $n; $i++) {
            $pentagonal[$i] = (3 * $i ** 2 - $i) / 2;
        }
        return $pentagonal;
    }