Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Creating the b-file of the array https://oeis.org/A187783
- // This code uses the GMP library for big integers: http://php.net/manual/en/book.gmp.php
- // functions:
- function pascalDiag($m, $n) {
- $return = gmp_div_q(
- gmp_fact($m * $n),
- gmp_pow(
- gmp_fact($n),
- $m
- )
- );
- return gmp_strval($return);
- }
- function diagCoordinates($n) {
- $arr = array();
- for ($i = 0; $i < $n; $i++) {
- for ($j = 0; $j <= $i; $j++) {
- array_push($arr, array($j, $i - $j));
- }
- }
- return $arr;
- }
- // create array:
- $num = 55; // For higher numbers, the entries in the b-file would have more than 1000 digits.
- $arr = array();
- for ($i=0; $i<=$num; $i++) {
- $row = array();
- for ($j=0; $j<=$num-$i; $j++) {
- array_push($row, pascalDiag($i,$j));
- }
- array_push($arr, $row);
- }
- // create b-file:
- $coord = diagCoordinates($num-1);
- $coordLen = count($coord);
- $str = '';
- for ($i=0; $i<$coordLen; $i++) {
- $val = $arr[ $coord[$i][0] ][ $coord[$i][1] ];
- $str .= $i . ' ' . $val . "\n";
- }
- echo $str;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement