Created
December 14, 2014 03:14
-
-
Save greydnls/6e7a7aa2d34b1f79bafe to your computer and use it in GitHub Desktop.
TofZGraph
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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