BrowserUk:

I didn't get anywhere on your binary string analysis problem yesterday. I was working on a couple different things, but none of 'em led me anywhere good. Anyway, for the fringe thing:

$ cat Fringe.pl #!/usr/bin/perl use strict; my $tree1 = [ 'd', [ 'c', [ 'a', 'b', ], ], ]; my $tree2 = [ [ 'd', 'c' ], [ 'a', 'b' ] ]; #my $tree2 = [ [ [ 'd', 'c', ], 'a', ], 'b', ]; my $ti1 = get_tree_iterator($tree1); my $ti2 = get_tree_iterator($tree2); my $cnt_mismatches=0; while (1) { my ($L, $R) = ($ti1->(), $ti2->()); ++$cnt_mismatches unless ($R eq $L) or (!$L and !$R); print "L=$L, R=$R\n"; last if !defined $L; } print $cnt_mismatches ? "$cnt_mismatches mismatches" : "TREES MATCH!", + "\n"; sub get_tree_iterator { my @stack = (shift); return sub { unshift @stack, @{shift @stack} while @stack and ref $stack[0] + eq 'ARRAY'; return shift @stack; } } $ perl Fringe.pl L=d, R=d L=c, R=c L=a, R=a L=b, R=b L=, R= TREES MATCH!

Update: I've posted a version (with the better iterator mentioned further down in this thread) to Rosetta Code. I couldn't find my original account information (or perhaps I misremembered and didn't create an account there. I didn't want to clutter up the thread with yet another version. I've also made that one meet the spec (i.e., early termination).

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re: Challenge: Perl 5: lazy sameFinge()? by roboticus
in thread Challenge: Perl 5: lazy sameFringe()? 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.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, 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, summary, 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.