#!/usr/bin/perl -- # Config my $trissize=250; # Init my $x=$trissize; my $y=$trissize; my %tris; my $block="#"; my $empty=" "; # Directions my @dir=(-1,0,0,-1,1,0,0,1); # Block generator follows... $blocksplaced=0; while(1) { if ($tris{"$x,$y"} ne $block) { $tris{"$x,$y"}=$block; $blocksplaced++; if ($blocksplaced == $trissize) { last; } } $d=int(rand(4))*2; $x+=$dir[$d]; $y+=$dir[$d+1]; } # Rest of the code is mostly for display. # Let's clean up the whitespace at the beginning # by finding the first non-empty column my $col=-1; for ($j=0;$j<=$trissize*2+1;$j++) { for ($i=0;$i<=$trissize*2+1;$i++) { if ($tris{"$i,$j"}) { $col=$j; last; } } if ($col>=0) { last;} } # Now print all nonempty rows from the first nonempty column, # discarding trailing whitespace. for ($i=0;$i<=$trissize*2+1;$i++) { $row=""; for ($j=$col;$j<=$trissize*2+1;$j++) { if (!$tris{"$i,$j"}) { $row.=$empty; } else { $row.=$tris{"$i,$j"}; } } $testrow=$row; $testrow =~ s/\s//g; $row=~ s/\s+$//; if ($testrow) { print $row."\n"; } $row=""; }