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

22245Re: Finding gaps in a sequence

Expand Messages
  • joy8388608
    Nov 17, 2011
    • 0 Attachment
      --- In ntb-clips@yahoogroups.com, "joy8388608" <mycroftj@...> wrote:
      >
      > Oh I love this type of problem so I had to submit my entry!
      >
      > I am viewing the three digits as a number in base 26 and thinking something like "if the line I'm on has a value of x, the next line should have a value of x+1.
      >
      > I keep calculations to a minimum and think the code is relatively easy to follow\modify.
      >
      > Note: VIS stand for Value IS and VSB is Value Should Be.
      >
      > Joy
      >
      > GapFind
      > ; Finds gaps in series aaa aab...aaz aba abb...
      > ^!Set %GapCount%=0
      > ^!Set %Line%=1
      > ^!Set %VSB%=^$ConvertTo26(^$StrCopyLeft("^$GetLine(^%Line%)$";3)$)$
      > ^!Set %AZ%="abcdefghijklmnopqrstuvwxyz"
      > ^!SetWordWrap OFF
      >
      > :LoopStart
      > ^!If ^%Line% > ^$GetLineCount$ LoopEnd
      > ^!If ^$StrSize("^$GetLine(^%Line%)$")$<2 LoopEnd
      > ^!Set %VIS%=^$ConvertTo26(^$StrCopyLeft("^$GetLine(^%Line%)$";3)$)$
      > ^!If ^%VSB%=^%VIS% OK else NOTOK
      >
      > :OK
      > ^!Inc %Line%
      > ^!Inc %VSB%
      > ^!Goto LoopStart
      >
      > :NOTOK
      > ^!Set %VSB%=^$ConvertTo26(^$StrCopyLeft("^$GetLine(^%Line%)$";3)$)$
      > ^!SetCursor ^%Line%:1
      > ^!InsertText ----- THERE IS A GAP HERE -----^%NL%
      > ^!Inc %Line%
      > ^!Inc %Line%
      > ^!Inc %VSB%
      > ^!Inc %GapCount%
      > ^!Goto LoopStart
      >
      > :LoopEnd
      > ^!Prompt ^%GapCount% gaps were found
      >
      > _ConvertTo26
      > ^!Set %Passed%=^&
      >
      > ^!Set %C1%=^$strIndex("^%Passed%";1)$
      > ^!Set %C2%=^$strIndex("^%Passed%";2)$
      > ^!Set %C3%=^$strIndex("^%Passed%";3)$
      >
      > ^!Set %V1%=^$StrPos("^%C1%";"^%AZ%";False)$
      > ^!Set %V2%=^$StrPos("^%C2%";"^%AZ%";False)$
      > ^!Set %V3%=^$StrPos("^%C3%";"^%AZ%";False)$
      >
      > ^!Result ^$Calc(^%V1%*676 + ^%V2%*26 + ^%V3%)$
      >

      I realized I made two slight errors in my program. The original code works as is but the Set %AZ% line should be moved up one click to come before the Set %VSB% line and the value of %AZ% should be "bcdefghijklmnopqrstuvwxyz" (remove the "a"). This makes the conversion to decimal truly base 26 using the 26 "digits" a-z with values 0-25. The original code used values 1-26 which is technically not correct.

      Joy
    • Show all 29 messages in this topic