### Comment on

 Need Help??

I am not sure if I add a new approach as I have not studied all posts in this thread in much detail. My code is just a bit shorter and I think a pretty direct approach to the problem.

use strict; use warnings; sub prepare { my( \$subtree, \$level, \$col, \$graph ) = @_; my \$lcol = 0; if( ref(\$subtree) ) { \$lcol = prepare( \$subtree->[0], \$level+1, \$col, \$graph ); # par +se left side of tree, keep top position \$lcol and \$graph->[\$level]->[\$_] = '_' for \$lcol..\$\$col-1; # dra +w horizontal line \$graph->[\$level]->[\$\$col++] = '/'; \$lcol = \$\$col; # new + root of the tree \$graph->[\$level]->[\$\$col++] = '\\'; my \$rcol = prepare( \$subtree->[1], \$level+1, \$col, \$graph ); # par +se right side of the tree, keep its top position \$rcol and \$graph->[\$level]->[\$_] = '_' for \$lcol+1..\$rcol-1; # dra +w horizontal line } else { \$graph->[\$level]->[\$\$col++] = \$subtree; # lea +f } return \$lcol; # ret +urn column of root } my \$root = do { my \$r; my @a = ( 'a'..'z', 1..9, 'A'..'Z' ); \$r = int( rand \$#a ), splice @a, \$r, 2, [ @a[ \$r, \$r+1 ]] while @a + > 1; \$a[0]; }; my @graph; my \$col = 0; prepare( \$root, 0, \\$col, \@graph ); for my \$row ( @graph ) { print \$_ // ' ' for @\$row; print "\n"; }

UPDATE: Here is some sample output for a smaller tree:

_____/\_ +_ __________________________/\__ +/\__ ____________________/\________ /\ x + /\ __/\________ _____/\___________ v w + y z __/\ _____/\__ /\__ __/\__ __/\ e /\__ /\__ m /\ _____/\ /\ __/\ d f /\ i /\__ n o /\__ s t u /\ c g h j /\ p /\ a b k l q r

In reply to Re: Challenge: Dumping trees. by hdb
in thread Challenge: Dumping trees. by BrowserUk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

• Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
• Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
• Read Where should I post X? if you're not absolutely sure you're posting in the right place.
• Posts may use any of the Perl Monks Approved HTML tags:
a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
• You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
 For: Use: & & < < > > [ [ ] ]
• Link using PerlMonks shortcuts! What shortcuts can I use for linking?

Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (2)
As of 2017-08-22 10:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Who is your favorite scientist and why?

Results (333 votes). Check out past polls.

Notices?