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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |