Skip to content

Instantly share code, notes, and snippets.

@Antti
Created March 15, 2017 20:44
Show Gist options
  • Save Antti/e61c0731f45329fe771146514c7352e9 to your computer and use it in GitHub Desktop.
Save Antti/e61c0731f45329fe771146514c7352e9 to your computer and use it in GitHub Desktop.
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