Skip to content

Instantly share code, notes, and snippets.

@diodoe
Created October 15, 2010 15:03
Show Gist options
  • Save diodoe/628330 to your computer and use it in GitHub Desktop.
Save diodoe/628330 to your computer and use it in GitHub Desktop.
create a numeric pyramid with random numbers
<?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