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

22305Re: Finding gaps in a sequence

Expand Messages
  • joy8388608
    Dec 7, 2011
    • 0 Attachment
      --- In ntb-clips@yahoogroups.com, "flo.gehrke" <flo.gehrke@...> wrote:
      >
      > --- In ntb-clips@yahoogroups.com, "joy8388608" <mycroftj@> wrote:
      > >
      > > Flo -
      > >
      > > Very interesting. Your clip is much faster than mine even
      > > when I turned ScreenUpdate off. Mine took 41 seconds and
      > > yours took 15 for 17550 lines (aaa to zzz with 26 .rr lines
      > > removed). Why? I'm not sure...
      >
      > > Flo -
      > >
      > > Very interesting. Your clip is much faster than mine even when
      > > I turned ScreenUpdate off. Mine took 41 seconds and yours took
      > > 15 for 17550 lines (aaa to zzz with 26 .rr lines removed). Why?
      > > I'm not sure...
      >
      > Joy,
      >
      > I think there are three main reasons for that:
      >
      > 1. Assigning the whole list to an array
      >
      > 2. Calculating ^$ConvertTo26$ only twice -- it's done three times in your clip
      >
      > 3. Gathering up the gaps with ^!Append and outputting them all at once -- no ^!InsertText
      >
      > > I wrote a quick clip to generate the lines aaa to zzz. Let
      > > me know if anyone wants me to post the code.
      >
      > I put my hand up and would enjoy seeing that clip!
      >
      > Flo
      >

      My pleasure. Joy

      Generate Base 26 numbers
      ; by Joy
      ^!Continue This will generate 17576 lines from aaa to zzz.

      ^!SKIP Leave Screen update on? (Slower...)
      ^!Setscreenupdate OFF
      ^!StatusShow Generating sequences aaa to zzz...

      ; Start with aaa
      ^!Set %I%=-1

      :LoopStart
      ^!Inc %I%
      ^!Set %Num%=^%I%

      ; Find value of first digit (of 3) (will be 0 to 25)
      ^!Set %x%=^$Calc(INT(^%Num%/676))$

      ; Convert first digit to letter (will be a to z)
      ^!Set %B26%=^$DecToChar(^$Calc(^%x%+97)$)$

      ; adjust value of current number
      ^!Set %Num%=^$Calc(^%Num% - (^%x%*676))$

      ; Find value of second digit (of 3) (will be 0 to 25)
      ^!Set %x%=^$Calc(INT(^%Num%/26))$

      ; Convert second digit to letter (will be a to z) and append
      ^!Set %B26%=^%B26%^$DecToChar(^$Calc(^%x%+97)$)$

      ; adjust value of current number
      ^!Set %Num%=^$Calc(^%Num% - (^%x%*26))$

      ; Convert remaining value (0 to 25) to letter (will be a to z) and append
      ^!Set %B26%=^%B26%^$DecToChar(^$Calc(^%Num%+97)$)$

      ; Output value
      ^!InsertText ^%B26%^%NL%

      ^!If "^%B26%" <> "zzz" LoopStart

      ^!Sound SystemExclamation
    • Show all 29 messages in this topic