22282Re: Finding gaps in a sequence

Expand Messages
• Dec 1, 2011
Thanks, Eb! Now we've got another working solution.

I've tested it succesfully. In a list of 10,000 3-digit-alpha-codes it needs 118 seconds to find a gap.

Maybe it's a bit complicated to see those gaps because it outputs numbers and not the code -- but never mind. What matters here is the basic concept.

Flo

--- 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!
>
> I believe you already had a base-26 suggestion. But I was on a roll and created my own version, looking at two ideas:
>
> 1. a single array, containing the base-26 values 0..25, used with the calc function, to arrive at consecutive decimal values for your alpha codes.
>
> 2. Three separate arrays, one for each digit in your codes, containing look-up values for each alpha character by digit.
>
> The second version is more efficient, and I have included it here (mind the long lines):
>
>
> ----------->8-------------
> H="ThreeDigitAlphaToBase26"
> ;value of characters in 1st to 3rd (right to left) digit of code
> ^!SetArray %digits3%=0;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;21;22;23;24;25
> ^!SetArray %digits2%=0;26;52;78;104;130;156;182;208;234;260;286;312;338;364;390;416;442;468;494;520;546;572;598;624;650
> ^!SetArray %digits1%=0;676;1352;2028;2704;3380;4056;4732;5408;6084;6760;7436;8112;8788;9464;10140;10816;11492;12168;12844;13520;14196;14872;15548;16224;16900
> ^!Set %offset%=64
> ;note: offsets a to 1, which has value zero in numbering system
> ;--------------------------------------------
> ;extract codes
> ^!SetListDelimiter ^%nl%
> ^!SetArray %codes%=^\$GetDocMatchAll("^[a-z]{3}")\$
> ;loop codes
> ^!Set %i%=0
> :Loop
> ^!Inc %i%
> ;fetch code digits one at a time, consolidate in temp
> ^!Set %one%=^\$CharToDec(^\$StrUpper(^\$StrIndex("^%codes^%i%%";1)\$)\$)\$
> ^!Dec %one% ^%offset%
> ^!Set %temp%=^%digits1^%one%%
> ^!Set %two%=^\$CharToDec(^\$StrUpper(^\$StrIndex("^%codes^%i%%";2)\$)\$)\$
> ^!Dec %two% ^%offset%
> ^!Inc %temp% ^%digits2^%two%%
> ^!Set %tre%=^\$CharToDec(^\$StrUpper(^\$StrIndex("^%codes^%i%%";3)\$)\$)\$
> ^!Dec %tre% ^%offset%
> ^!Inc %temp% ^%digits3^%tre%%
> ;assign assembled code back to codes array
> ^!Set %codes^%i%%=^%temp%
> ;--------------------------------------------
> :gap_trap
> ^!If ^%i%>1 SKIP_2
> ^!Set %OLD%=^%temp%
> ^!Dec %old%
> ;incrementing OLD should set it to same as new
> ^!Inc %OLD%
> ;temporarily disable for testing
> ^!If ^%old%<>^%temp% HANDLE_GAP
> ;if differene > 1 signal a gap
> ;--------------------------------------------
> :NOGAP
> ^!Set %old%=^%temp%
> ^!Info ^%codes^%i%%
> ^!If ^%i%<^%codes0% LOOP
> ^!Goto END
>
> :HANDLE_GAP
> ^!Info [L]There is a gap at ^%old% to ^%temp%^%nl%Continuing...
> ^!Set %OLD%=^%TEMP%
> ^!Goto NOGAP
> ----------->8-------------
>
>
> Cheers,
>
>
> Eb
>
> PS
> I'm guessing at some of the stuff below:
> The conversion to hex failed because NoteTab saw the insertion of a plain caret as the begin of a parsable something, and when changed to ^%caret% in included the caret like an escaped character, no longer capable of triggering the parser.
>
> As to the HextToInt function, it works fine, when an actual hex number is passed to it.
>
• Show all 29 messages in this topic