Created
October 15, 2010 15:03
-
-
Save diodoe/628330 to your computer and use it in GitHub Desktop.
create a numeric pyramid with random numbers
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 | |
//You'd find it useful to resolve the http://bit.ly/aySVgM problem ;) | |
//Number of total rows | |
$tot_row=100; | |
//Spacer between the numbers | |
$spacer=' '; | |
//file where the pyramid will be saved | |
$file='triangle.txt'; | |
$tbl=array(); | |
$pyramid=''; | |
for($i=1; $i<=$tot_row;$i++){ | |
for($e=1;$e<=$i;$e++) $tbl[$i][]=rand(1,9); | |
$row_limit=''; | |
for($r_s=1;$r_s<=$tot_row-$i;$r_s++) $row_limit.=$spacer; | |
$pyramid.=$row_limit.trim(implode($spacer,$tbl[$i]),$spacer)."\n"; | |
} | |
file_put_contents($file,$pyramid); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment