yes, it would not be fair if everyone were allowed to report their own times. code should be submitted before the event and all entries will be times at the meetup with my MacBook Pro using the 32 bit version of q.
Noel has provided a very good first cut. I ask that we don’t share our solutions until after the meetup. I will report the winning entry and also the fastest algorithm from those who could not attend the meetup. can anyone beat Attila?
in the case of a tie, the shortest solution wins. in addition, global variables can not be used.
Using the HKIDs from the above page, Nick will confirm correctness:
q)ids:(“B123456”;“A182361”;“CA182361”;“AB123456”;“ZA182361”;“AZ182361”;“XZ182361”;“ZX182361”;“XX182361”)
q)“651936862”~hkidcheck each ids
1b
Is this to be taken literarily? If so one can come up with fast but useless solutions that satisfy this correctness test
q)“651936862”~hkidcheck each ids
1b
q)
q)\ts:1000 hkidcheck each ids
2 432
Otherwise the (i) length of the input HKID list and (ii) whether it contains duplicates will have a significant impact on determining the most efficient solution
Thanks,
Alex
P.S. OK I just read about the ban on global variables which may (?) make my last comment irrelevant. Still only participants who will have read this thread will know about this additional constraint
yes, it is true that a better test of the submitted function’s accuracy would be to run the function across all possible HKIDs.
a one or two letter prefix and a 6 digit number results in a list of 373,071,582 values. in addition to putting a very high limit on the HK population, it also makes it slow to test all possible combinations. (not to mention the fact that i can’t even generate the complete list of hkids without maxing out the memory on my machine.)
the supplied test helps ensure your submission is accurate.
there have been submissions that incorrectly include the possibility of a “B” checkdigit. the following example test for this case:
> Otherwise the (i) length of the input HKID list and (ii) whether it contains duplicates will have a significant impact on determining the most efficient solution
The algorithm complexity is O(n), n=strlen(hkid)=7 or 8. The spreadsheet below illustrates the thought process. I did some peephole optimizations and micro-benchmarks as well. Nick Psaris wrote a great book. Thanks First Derivatives for sponsoring.