Skip to content

Instantly share code, notes, and snippets.

@greydnls
Created December 14, 2014 03:14
Show Gist options
  • Save greydnls/6e7a7aa2d34b1f79bafe to your computer and use it in GitHub Desktop.
Save greydnls/6e7a7aa2d34b1f79bafe to your computer and use it in GitHub Desktop.
TofZGraph
<?php
/**
* Created by PhpStorm.
* User: kayladnls
* Date: 12/13/14
* Time: 9:38 PM
*/
// for each row, go up one left one + up one right 2
$rows = array();
$line1 = array(1);
$rows[] = $line1;
$iterations = 25;
echo "1\n";
for ($row = 1; $row< $iterations; $row++)
{
$line = array();
for($column = 0; $column <= $row; $column++)
{
$first_number = isset($rows[$row - 1 ][$column - 1 ]) ? $rows[$row - 1 ][$column - 1 ] : 0;
$second_number = isset($rows[$row - 1 ][$column + 2 ]) ? $rows[$row - 1 ][$column + 2 ] : 0;
$val = $first_number + $second_number;
echo $val."\t";
$line[] = $val;
}
$rows[] = $line;
echo "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment