Created
April 17, 2022 07:28
-
-
Save rvente/a8baee476d37f63dc1141186533c7f9d to your computer and use it in GitHub Desktop.
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
import itertools | |
def decode_multi_tap(multitap_encoded: str): | |
if not multitap_encoded.replace(" ", "").isdecimal(): | |
return "" | |
if "1" in multitap_encoded: | |
return "" | |
t9_map = { | |
"2" : "abc", | |
"3" : "def", | |
"4" : "ghi", | |
"5" : "jkl", | |
"6" : "mno", | |
"7" : "pqrs", | |
"8" : "tuv", | |
"9" : "wxyz", | |
} | |
output = "" | |
for root, occurences in itertools.groupby(multitap_encoded): | |
if root == " ": | |
continue | |
output += t9_map[root][len(list(occurences))-1] | |
return output | |
if __name__ == "__main__": | |
tests = [ | |
"55544488833", | |
"5552884 44", | |
"55566688833", | |
] | |
for test in tests: | |
print(decode_multi_tap(test)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment