ikegami,

Below is some "detector" code that works along the lines as I mentioned above. It determines whether or not I should remove a pair. Its crude because I've ripped it from another function I've written that does a little something different, and the data structures may look a little odd because of that. Hmm... now that I test this further I wonder if I actually had the answer all along, I'll try and come up with an example that doesn't work with this code and report back.

sub pseudoKnotPairs { my $self = shift; my %p = @_; my @r; print "\n\n"; my $hel; my $h = 0; my @keys = sort {$a <=> $b} keys %p; map { $hel->{$h} = [$_, $p{$_}]; $h++} (@keys); # set some flags my $reset = 0; foreach my $k (sort {$a <=> $b} keys %{$hel}) { print $k, " ", @{$hel->{$k}}[0], " ", @{$hel->{$k}}[1], ": "; + my $nested = 1; my $cl = @{$hel->{$k}}[1]; for (my $c = $k+1; $c < $#keys + 1; $c++) { print " $cl"; if (@{$hel->{$c}}[1] > @{$hel->{$k}}[1]) { if (@{$hel->{$k}}[1] > @{$hel->{$c}}[0] ) { $nested =0 + } last; } if ( $cl < @{$hel->{$c}}[1]) { $nested = 0; } $cl = @{$hel->{$c}}[1]; } # some @r value set below to be returned if ($nested == 1) { print "\tok!"; } else { print "\tremove me!"; } print "\n"; } print "\n\n"; return 1; } &pseudoKnotPairs(qw/0 9 3 6 4 5 7 10 8 11/);
cheers,
M

In reply to Re^2: (non) nested pairs by xipho
in thread (non) nested pairs by xipho

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.