Skip to content

Instantly share code, notes, and snippets.

Avatar
🛠️
Rust Tinkering

Michał Fita michalfita

🛠️
Rust Tinkering
View GitHub Profile
@michalfita
michalfita / kpcnv.rb
Created Dec 28, 2021
Ruby solution to conversion of text & digits into a phone number or back (bidirectional conversion)
View kpcnv.rb
def kpcnv(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-1
l = text[ti]
if l.ord >= 48 and l.ord <= 57 then
for ni in 0..numbers.length-1
if numbers[ni] == l.to_i
@michalfita
michalfita / text2number.rb
Last active Dec 28, 2021
Ruby solution to conversion of text into a phone number
View text2number.rb
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