Created
March 15, 2017 20:44
-
-
Save Antti/e61c0731f45329fe771146514c7352e9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
LETTER_MAP = ('a'..'z').to_a | |
def decode_word_faster(word, current_word=[], words=[]) | |
if word.size == 0 # we reached the end of word | |
words.push(current_word.map{ |letter| LETTER_MAP[letter-1] }.join) | |
return words | |
end | |
decode_word_faster(word[1..-1], current_word.clone.push(word[0].to_i), words) | |
if word.size > 1 && (word[0..1].to_i < 26) | |
decode_word_faster(word[2..-1], current_word.clone.push(word[0..1].to_i), words) | |
end | |
return words | |
end | |
p decode_word_faster('2114111925') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment