## 22283Re: Finding gaps in a sequence

Expand Messages
• Dec 1, 2011
Joy,

I also went through your clip again (messages #22230, #22245). I like that formula '^\$Calc(^%V1%*676 + ^%V2%*26 + ^%V3%)\$' which, actually, seems to be the heart of your solution.

So I combined it with some ideas of my first concept and managed to speed up your clip significantly. Originally, your clip needed 78 seconds (on my notebook) to check a list of 10,000 codes. The following version is doing it in 9 seconds:

^!SetHintInfo Working...
; Assign code list to array %List%
^!SetListDelimiter ^%NL%
^!SetArray %List%=^\$GetText\$
^!Set %AZ%="abcdefghijklmnopqrstuvwxyz"
^!Set %i%=1

:CodeToInt
; Save current code to variable for later output in case of gap
^!Set %CurrCode%=^%List^%i%%
; Convert code to number(with Joy's formula)
^!Set %First%=^\$Convert(^%List^%i%%)\$
^!Inc %First%
^!Inc %i%
^!If ^%i% > ^%List0% Out
^!Set %Second%=^\$Convert(^%List^%i%%)\$
^!IfSame ^%First% ^%Second% CodeToInt Else False

:False
^!Append %Gaps%=^%CurrCode%^P
^!Goto CodeToInt

:Out
^!IfEmpty ^%Gaps% Next Else Skip_2
^!Info No gaps!
^!Goto Skip_3
^!Toolbar New Document
^!InsertText Gap found after...^P^%Gaps%
^!Toolbar Second Window
^!ClearVariables

The sublip with custom function ^\$Convert\$ and your formula is...

^!Set %C1%=^\$StrIndex(^&;1)\$
^!Set %C2%=^\$StrIndex(^&;2)\$
^!Set %C3%=^\$StrIndex(^&;3)\$
^!Set %V1%=^\$StrPos(^%C1%;^%AZ%;0)\$
^!Set %V2%=^\$StrPos(^%C2%;^%AZ%;0)\$
^!Set %V3%=^\$StrPos(^%C3%;^%AZ%;0)\$
^!Result ^\$Calc(^%V1%*676 + ^%V2%*26 + ^%V3%)\$

Thanks again for your proposal! Maybe you'll have a look at this revised version...

Regards,
Flo

--- In ntb-clips@yahoogroups.com, "joy8388608" <mycroftj@...> wrote:
>
>
>
> --- In ntb-clips@yahoogroups.com, "Eb" <ebbtidalflats@> wrote:
> >
> > Hi Flo,
> >
> > You have are right in what the hex conversion was supposed to do.
> > In the mean time I found my original char to hex clip, which only converted a single digit. I applied the single-digit approach to your problem. While I got it to work, it just raised another problem.
> >
> > The alphabet is like a base-26 number set (English aplhabet), after shifting a to zero. Straight conversion to numbers creates gaps, where it rolls to the next digit, i.e. aaz --> aba has a gap of 26!, the value of the next digit, and azz to baa has a gap much larger!
>
>
> Sorry if I misunderstood you but I'll reply just in case in order to save you possible extra work and confusion...
>
> You said aaz to aba has a gap but you correctly noted a=0...z=25.
> Therefore, aaz=(0*26^2 + 0*26 + 25)=25 and aba=(0*26^2 + 1*26 + 0)=26 - No gap. Likewise, azz=675 and baa=676. Again, no gap.
>
> Hope this helps, sorry if I misunderstood.
>
> Joy
>
• Show all 29 messages in this topic