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

22230Re: Finding gaps in a sequence

Expand Messages
  • joy8388608
    Nov 14, 2011
    • 0 Attachment
      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.


      ; 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

      ^!If ^%Line% > ^$GetLineCount$ LoopEnd
      ^!If ^$StrSize("^$GetLine(^%Line%)$")$<2 LoopEnd
      ^!Set %VIS%=^$ConvertTo26(^$StrCopyLeft("^$GetLine(^%Line%)$";3)$)$
      ^!If ^%VSB%=^%VIS% OK else NOTOK

      ^!Inc %Line%
      ^!Inc %VSB%
      ^!Goto LoopStart

      ^!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

      ^!Prompt ^%GapCount% gaps were found

      ^!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%)$
    • Show all 29 messages in this topic