Loading ...
Sorry, an error occurred while loading the content.

22228Re: Finding gaps in a sequence

Expand Messages
  • diodeom
    Nov 13, 2011
    • 0 Attachment
      Flo wrote:
      >
      > Just for the fun of it, I would like to present my first approach. It's dealing with a pure list of 3-digit-alpha-codes from 'aaa' to 'zzz' without any further stuff in the lines.
      >
      > It's quite fast as well since it doesn't move from line to line but assigns the whole list to an array. The result is a list of codes with gaps, i.e. codes that do not immediately follow one another displayed in a second window (avoid empty line at end of list):
      >
      > (...)
      >
      > ^!Set %Diff%=^$Calc(^%y%-^%x%)$
      > ^!If ^%Diff% = 1 Skip Else Next
      > ^!If ^%Diff%=-24 Next Else Error
      >


      It looks like to prevent erroneus gap reporting between the pairs like azz/baa, bzz/caa, czz/daa, etc., one more provision could help (when ^%Diff%=-49).

      - - -
      As you pointed out, looping in memory ought to be incomparably faster than taking an illustrative walk over the displayed lines (for either of the index-comparing methods), but for those of us who find rapid regex swaps on 'live' text appealing :) here's yet another exercise in gap-sniffing that doesn't directly evaluate any of the indices; it checks instead for presence of any sequence-breaking patterns.

      The first simple replacement iteration does the vast majority of spotting -- and I wish it were it, but the 'bloat' of the subsequent ones is needed to locate any remaining cases (in a quickly diminishing order of probablity of their occurence):

      ^!SetArray %az%=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;a
      ^!Set %i%=0

      :3rd
      ^!Inc %i%
      ^!If ^%i%=27 2_nd
      ^!Set %j%=^$Calc(^%i%+1)$
      ;Flag where 3rd chars skip the sequence
      ;(e.g. zbx/zbz, zbz/zcb)
      ^!Replace "^%az^%i%%\R\K(?!(\*|..^%az^%j%%|\R|\Z))" >> "*****\r\n" WARS
      ^!Goto 3rd

      :2_nd
      ;Flag where after 3rd [a-y] the next 2nd doesn't remain the same
      ;(e.g. zcc/zdd, zdd/zfe)
      ^!Replace "(.)[a-y]\R\K(?!.(\*|\1|\R|\Z))" >> "*****\r\n" WARS
      ^!Set %i%=0
      :2nd
      ^!Inc %i%
      ^!If ^%i%=27 1_st
      ^!Set %j%=^$Calc(^%i%+1)$
      ;Flag where 3rd 'z' doesn't incremeant by one the next 2nd
      ;(e.g. aaz/aca, zez/zga)
      ^!Replace "^%az^%i%%z\R\K(?!.(\*|^%az^%j%%|\R|\Z))" >> "*****\r\n" WARS
      ^!Goto 2nd

      :1_st
      ;Flag where after 2nd [a-y] the next 1st doesn't remain the same
      ;(e.g. bcc/dcd, dcd/gce)
      ^!Replace "^(.)[a-y].\R\K(?!(\*|\1|\R|\Z))" >> "*****\r\n" WARS
      ^!Set %i%=0
      :1st
      ^!Inc %i%
      ^!If ^%i%=26 End
      ^!Set %j%=^$Calc(^%i%+1)$
      ;Flag where 'zz' doesn't incremeant by one the next 1st
      ;(e.g. azz/caa, czz/faa)
      ^!Replace "^%az^%i%%zz\R\K(?!(\*|^%az^%j%%|\R|\Z))" >> "*****\r\n" WARS
      ^!Goto 1st
    • Show all 29 messages in this topic