Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: Challenge: Dumping trees.

by Anonymous Monk
on Oct 15, 2012 at 17:14 UTC ( #999127=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Challenge: Dumping trees.
in thread Challenge: Dumping trees.

I also finally succeeded

neat :) it really is much easier on the eyes

Upon further testing, the anomalies

Hmm, weird. Using your tree generator

from genBiaryTree
my $root = do { our $S //= 0; srand $S if $S; 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 = @{ $a[0] }; \@a; };
And running

I was not able to reproduce the anomalies, I get


Comment on Re^3: Challenge: Dumping trees.
Select or Download Code
Re^4: Challenge: Dumping trees.
by BrowserUk (Pope) on Oct 15, 2012 at 20:58 UTC
    I was not able to reproduce the anomalies,

    Okay.

    1. First problem: Your version of the generator is not -- for the same setting of srand-- producing the same randomly generated tree.

      At first, I assumed this must be because you were using a different rand to me. I guessed you might be running on some flavour of *nix -- but then I noticed your use of notepad above -- which squashed that idea.

      Then I thought you might be running some other flavour of windows perl -- perhaps Strawberry. So, I thought I'd re-generate the failing test cases using my version of the generator and supply you with the generated trees.

    2. Second problem: my version of the generator is no longer producing the same trees for a given value of -S=nnn!

      Did I change the generator between posting and now? I don't remember, but I can only assume that something in the original code I used, that used rand has changed.

      Never mind: I'll reverse engineer the output I posted back to a raw tree structure and give you that.

    3. Third problem: Reverse engineering this pretty form of output is extremely painstaking, laborious and painful!

      But I did it!

      my $root = [ [ ['a','b'], [ [[['c','d'],[['e','f'],'g']],[['h',['i',['j','k']]],'l']], [['m',['n',['o','p']]],'q'] ] ], [ [ [ [[[['r',[['s','t'],'u']],'v'],['w','x']],[['y','z'],]], [ ['1',[['2','3'],[['4','5'],[['6',['7',['8','9']]],['A','B']]]]], [[['C','D'],['E','F']],'G'] ] ], [ [ [['H',[['I',['J','K']],'L']],[['M','N'],'O']], ['P',[[[['Q','R'],['S','T']],'U'],['V','W']]] ], ['X','Y'] ] ],'Z' ] ] ;

      Which fed to your dumper produces the same (malformed) dump that I originally posted:

      C:\test>anonBinTreeDumper.pl _____________________________/\___________________________________ +___________________________________________________ _/\___________________ + ___________________________________/\ /\ _________/\_______ _________________ +______________/\_______________________________ Z a b _____/\_______ _____/\ ____/\________________ +_____ _______________/\_ _/\___ _____/\ /\_ q ___/\ _______________ +____/\_______ _____/\_ /\ /\ _/\ /\_ l m /\_ _/\_ _/ /\___ + ___/\ _______/\___ /\_________ X Y c d /\ g h /\_ n /\ _____/\ //\ 1 _/\___ + _/\_ G /\_____ _/\ P _/\_ e f i /\ o p /\___ v wyxz /\ _/\______ +_ /\ /\ H ___/\ /\ O ___/\ /\ j k r _/\ 2 3 /\ _____ +/\_ C D E F /\_ L M N _/\_ U V W /\ u 4 5 /\_ + /\ I /\ /\ /\ s t 6 /\_ + A B J K Q R S T 7 /\ 8 9

      But that raises another problem...

    4. Fourth problem: if you look at the raw tree above, you'll see it is malformed: [['y','z'],]; the x,y node is paired with a null node.

      And that raises the final problem.

    5. Fifth problem: Given that the raw tree is reproduced from the pretty-printer output, there is no way to determine if the tree my generator fed your dumper was malformed; or if the malformation is a result of occlusion in the dumper output?

      I don't think that it is possible for the generator to produce bad trees -- but I haven't proven that.

      Looking at the spacing between the 'z' and the '1' nodes, the gap is too big, which makes me think it is a artifact of the dumper.

    At that point, I manually made the simplest correction to the raw tree that (I thought) would make it valid:

    and re-ran the dumper. As you can see, it still produces the identical, malformed dump:

    C:\test>anonBinTreeDumper.pl _____________________________/\___________________________________ +___________________________________________________ _/\___________________ + ___________________________________/\ /\ _________/\_______ _________________ +______________/\_______________________________ Z a b _____/\_______ _____/\ ____/\________________ +_____ _______________/\_ _/\___ _____/\ /\_ q ___/\ _______________ +____/\_______ _____/\_ /\ /\ _/\ /\_ l m /\_ _/\_ _/ /\___ + ___/\ _______/\___ /\_________ X Y c d /\ g h /\_ n /\ _____/\ //\ 1 _/\___ + _/\_ G /\_____ _/\ P _/\_ e f i /\ o p /\___ v wyxz /\ _/\______ +_ /\ /\ H ___/\ /\ O ___/\ /\ j k r _/\ 2 3 /\ _____ +/\_ C D E F /\_ L M N _/\_ U V W /\ u 4 5 /\_ + /\ I /\ /\ /\ s t 6 /\_ + A B J K Q R S T 7 /\ 8 9

    So then I fed that corrected tree to my dumper:

    C:\test>perl \perl64\site\lib\Tree\Dump.pm ____________________________________________________ +_________________________________ _____________/ + \___________________ _/ \_________ __________ +_________________________________/ \ / \ _____/ \_____ _______/ + \_______________ Z a b ___/ \_____ _/ \ _____/ \__________ +___________ ___/ \_ _/ \_ _/ \ / \_ q _/ \ ___/ + \___ _______/ \_________ / \ / \ _/ \ / \_ l m / \_ ___/ \_ _/ / \___ + _/ \ ___/ \_ / \_ X Y c d / \ g h / \_ n / \ ___/ \ / \ / \ 1 _/ \___ + _/ \_ G / \___ _/ \ P ___/ \_ e f i / \ o p / \_ v w x y z / \ _/ \__ +___ / \ / \ H _/ \ / \ O _/ \ / \ j k r _/ \ 2 3 / \ _/ + \_ C D E F / \_ L M N _/ \_ U V W / \ u 4 5 / \_ + / \ I / \ / \ / \ s t 6 / \ +_ A B J K Q R S T 7 / + \ 8 + 9

    At this point, I'm kicking the ball into your court to decide if it is worth pursuing further?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    RIP Neil Armstrong

      ..But I did it!...At this point, I'm kicking the ball into your court to decide if it is worth pursuing further?

      I see, thanks. Nope, definitely not worth pursuing Fudgy further.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://999127]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2014-09-03 03:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (35 votes), past polls