T. Onoma
11/6/2004 9:28:00 PM
Thanks all for the responses. Looks like it _might_ be doable, but the
complexity quickly racks up. The presented quick stabs at it fail on capital
letters and other characters.
Running away might be the best course of action ;)
T.
On Saturday 06 November 2004 09:38 am, gabriele renzi wrote:
| trans. (T. Onoma) ha scritto:
| > Is there an efficient way to calculate the "succ distance" between two
| > strings (without iterating over each succession)? Examples:
| >
| > 'a'..'a' 0
| > 'a'..'b' 1
| > 'a'..'z' 25
| > 'a'..'aa' 26
| >
| > T.
|
| my tentativ impl would be
| class String
| def value
| i=-26
| split(//).inject(0){|x,y|
| i+=26
| x+y[0]-?a+i
| }
| end
| end
|
| class Range
| def dist
| max.value - min.value
| end
| end
| p 'aa'.value - 'a'.value
| p 'a'.value - 'a'.value
| p ('a'..'b').dist
| p ('a'..'z').dist
|
| note that '-?a' could be moved in the 'i' initialization but I'm running
| away :)
--
( o _ ã?«ã?©ã?
// trans.
/ \ transami@runbox.com
I don't give a damn for a man that can only spell a word one way.
-Mark Twain
[8,16,20,29,78,65,2,14,26,12,12,28,71,114,12,13,12,82,72,21,17,4,10,2,95].
each_with_index{|x,i| $><<(x^'Begin landing your troops'[i]).chr}
-Tadayoshi Funaba