What is the fastest, most optimised way to determine where a letter falls into the alphabet (e.g. a = 1, z = 26)?
I know of a few ways to do it but I'm wondering if anyone has thought much about this and has a very fast solution?
the fastest method I can think of is to have a list with each item containing a letter, then running this script:
set [count v] to [0] set [searchChar v] to [x] repeat until <(item (count) of [letters v]) = (searchChar)> change [count v] by (1) endI wanted to add a < > or <(count) > [26])> to that, but scratchblocks was having none of it.
set [count v] to [0] reset timer set [searchChar v] to [z] repeat until <(item (count) of [letters v]) = (searchChar)> change [count v] by (1) end set [time v] to (timer)and in turbo-mode, this got me a time of 0.0 seconds for z...
Last edited by sparks (2012-03-02 13:28:00)
Offline
I suspect a bisection search would be quicker than a sequential search...but if you're happy with what you have, I'll just close this as you requested
Offline