Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Just another Perl shrine
 
PerlMonks  

hdb's scratchpad

by hdb (Parson)
on Mar 05, 2013 at 11:57 UTC ( #1021811=scratchpad: print w/ replies, xml ) Need Help??

If I ask Box 1 or Box 2 will you flash red? If I ask Box 1 will you flash green?
Box Response 1 2 3 Red/Green yes/no Red/Green Red/Red Green/Red no/yes Red/Green Red/Red Green/Red
DumpTree code:
use strict; use warnings; use constant { LEFT => 0, RIGHT => 1 }; sub prepare { my( $tree, $w, $lr, $level, $col, $canvas, $chars ) = @_; if( ref($tree) ) { my( $lcol, $rcol ) = map { $$col += $w*$_; prepare( $tree->[$_], $w, $_, $level+1, $col, +$canvas, $chars ) } LEFT, RIGHT; $canvas->[$level ]->[$lcol] = $$chars[LEFT]; $canvas->[$level-1]->[$_ ] = '_' for $lcol+1..$rcol- +1; $canvas->[$level ]->[$rcol] = $$chars[RIGHT]; return $lr ? $lcol : $rcol; } else { $canvas->[$level++]->[$$col] = $_ for split //, $tree; + return $$col; } } sub dumpTree { my ($col, @canvas ) = (1); my $width = $_[1] > 0 ? 1+$_[1] : 1; my $chars = $_[2] ? [ '|', '|' ] : [ '/', '\\' ]; prepare( $_[0], $width, RIGHT, 1, \$col, \@canvas, $chars ); return join( '', map { join( '', map { $_ // ' ' } @$_, "\n" ) + } @canvas ); } sub randomTree { my @t = @_; my $r; $r = int( rand $#t ), splice @t, $r, 2, [ @t[ $r, $r+1 ]] whil +e @t > 1; return $t[0]; } my @t1 = ( 'a'..'z' ); my @t2 = qw( Alpha Beta Gamma Delta Epsilon Zeta Eta Theta Iota Kappa +Lambda Mu Nu Xi Omicron Pi Rho Sigma Tau Upsilon Phi Chi Psi Ome +ga); print dumpTree( randomTree( @t1 ), 1 ); print dumpTree( randomTree( @t2 ), 3, 1 );
9833 ♩
9834 ♪
9835 ♫
9836 ♬
9837 ♭
9838 ♮
9839 ♯
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (11)
As of 2014-04-17 10:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (444 votes), past polls