杨辉三角

哦。。曾经的痛。。。。

<?php 

$arr = [1];
for ($i=0; $i < 10 ; $i++) {
    
    for ($j=0; $j < count($arr); $j++) { 
        echo $arr[$j];
        echo " ";
    }
    echo "<br>";
    $arr = getNext($arr);
}

function getNext($pre)
{
    array_push($pre, 0);
    array_unshift($pre, 0);
    $next = [];
    for ($i=0; $i < count($pre)-1; $i++) { 
        $next[] = $pre[$i] + $pre[$i+1];
    }
    return $next;
}

 

posted @ 2017-08-19 11:13  牛奶无花果  阅读(104)  评论(0编辑  收藏  举报