Sha256: f88a2d5cb19fe8bfeab61607fd35944db5f9064279a2b2e68d28aa57dec3735f
Contents?: true
Size: 533 Bytes
Versions: 226
Compression:
Stored size: 533 Bytes
Contents
<?php function pascalsTriangleRows($rowCount) { if ($rowCount < 0 || $rowCount === null) { return -1; } $output = []; if ($rowCount === 0) { return $output; } foreach (range(0, $rowCount-1) as $rowNum) { array_push($output, pascalRow($rowNum)); } return $output; } function pascalRow($n) { $line = [1]; if ($n === 0) { return $line; } foreach (range(0, $n-1) as $k) { array_push($line, $line[$k] * ($n-$k) / ($k+1)); } return $line; }
Version data entries
226 entries across 226 versions & 1 rubygems