Method: RubyLabs::HashLab#radix26
- Defined in:
- lib/hashlab.rb
#radix26(s) ⇒ Object
Compute the wighted sum of the ordinal values of characters in a string, where the weight for a character is defined by its position in the string: the weight for the character i positions from the right is 26**i. The numeric value of a character is determined by Fixnum#ord, an extension to the Fixnum class, which is defined in rubylabs.rb. Upper and lower case letters are mapped to integer from 0 to 25, while other characters are unchanged.
Examples:
>> radix26("be")
=> 30
>> radix26("bee")
=> 784
>> radix26("beetle")
=> 13792718
>> radix26("beethoven")
=> 242419173737
– :begin :radix26
54 55 56 57 58 59 60 |
# File 'lib/hashlab.rb', line 54 def radix26(s) x = 0 s.each_byte do |b| x = x * 26 + b.ord end return x end |