Last active
December 28, 2021 19:47
-
-
Save michalfita/06ce5e64a558ad809a52e597a67663e9 to your computer and use it in GitHub Desktop.
Ruby solution to conversion of text into a phone number
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
def n2t(text) | |
letters = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"," "] | |
numbers = [ 2 , 2, 2 , 3 , 3 , 3 , 4 , 4 , 4 , 5 , 5 , 5 , 6 , 6 , 6 , 7 , 7 , 7 , 7 , 8 , 8 , 8 , 9 , 9 , 9 , 9 , 0 ] | |
output = String.new() | |
for ti in 0..text.length | |
for li in 0..letters.length | |
if letters[li] == text[ti] then | |
output << numbers[li].to_s | |
end | |
end | |
end | |
print output | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment