This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Keybase proof | |
I hereby claim: | |
* I am nicholasdanks on github. | |
* I am nicholasdanks (https://keybase.io/nicholasdanks) on keybase. | |
* I have a public key ASBW2aRg6SKxF6IUGXdo60rVcrk2umNBWEnq82vVTo_nLQo | |
To claim this, I am signing this object: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ShortStringPacker | |
## Packs a short string into a Fixnum | |
# Arguments: | |
# str - String object | |
# Returns: a Fixnum object | |
def self.pack(str) | |
unpacked = str.chars.map{|c| c.ord - 'a'.ord + 1} | |
packed = unpacked.map.with_index{|c, i| c << (5 * i)}.reduce(:|) | |
end |