Skip to content

Instantly share code, notes, and snippets.

@codepo8
Last active November 23, 2023 09:57
Show Gist options
  • Save codepo8/9e7dcabb2a9b0c8f3c19441563c6318c to your computer and use it in GitHub Desktop.
Save codepo8/9e7dcabb2a9b0c8f3c19441563c6318c to your computer and use it in GitHub Desktop.

Thumbs up for the old school

If 44-33-555-555-666 is hello and 9-666-777-555-3 is world, what is:

9-33-0-2-777-33-0-3-33-888-33-555-666-7-33-777-7777 = ???

Can you do an encoder/decoder for this way of writing?

@GeorgeNikitinNV
Copy link

It is pretty obvious, that numbers between dashes encode letters, knowing the first two words, we can easily figure that the phrase is (? == unknown letter):

?-e-?-?-r-e-?-d-e-?-e-l-o-?-e-r-?

If we assume that 0 == space, then the phrase looks like

we are developers

In that case we also know some other letters. Putting them all together we have:

A=2
B=
C=
D=3
E=33
F=
G=
H=44
I=
J=
K=
L=555
M=
N=
O=666
P=7
Q=
R=777
S=7777
T=
U=
V=888
W=9
X=
Y=
Z=

It looks like it is pretty obvious what is missing, so the full solution looks like:

<SPACE>=0
A=2
B=22
C=222
D=3
E=33
F=333
G=4
H=44
I=444
J=5
K=55
L=555
M=6
N=66
O=666
P=7
Q=77
R=777
S=7777
T=8
U=88
V=888
W=9
X=99
Y=999
Z=9999
key = {
    " ": 0,
    "A": 2,
    "B": 22,
    "C": 222,
    "D": 3,
    "E": 33,
    "F": 333,
    "G": 4,
    "H": 44,
    "I": 444,
    "J": 5,
    "K": 55,
    "L": 555,
    "M": 6,
    "N": 66,
    "O": 666,
    "P": 7,
    "Q": 77,
    "R": 777,
    "S": 7777,
    "T": 8,
    "U": 88,
    "V": 888,
    "W": 9,
    "X": 99,
    "Y": 999,
    "Z": 9999,
}

string = input("Enter a string: ")

output = []
for l in string:
    try:
        code = key[l.upper()]
    except KeyError:
        code = "?"
    output.append(code)

print("-".join(str(x) for x in output))

@codepo8
Copy link
Author

codepo8 commented Nov 23, 2023

"W": 9,
"X": 99,
"Y": 999,
"Z": 9999,

}

string = input("Enter a string: ")

output = []
for l in string:
try:
code = key[l.upper()]
except KeyError:
code = "?"
output.append(code)

print("-".join(str(x) for x in output))

Love the lazy approach of not trying to detect the order in the string, but use a lookup table instead :)

@GeorgeNikitinNV
Copy link

it works 🤷‍♂️

@gpetrioli
Copy link

Here is (verbose) programmatic version 😀 (no UI)
https://gist.github.com/gpetrioli/cfc05bb447f2706f2de833c9cea4e351

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment