added beginnings of morse code problem
This commit is contained in:
parent
e97f4e31b8
commit
8c7b4e0deb
48
jt-dilema/dilema.py
Normal file
48
jt-dilema/dilema.py
Normal file
@ -0,0 +1,48 @@
|
||||
import sys
|
||||
|
||||
translate = {
|
||||
'._': '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',
|
||||
}
|
||||
|
||||
def mogrificate(l, your_index, r, sofars=None):
|
||||
if sofars is None:
|
||||
sofars = []
|
||||
for i in xrange(MIN_LEN, MAX_LEN + 1):
|
||||
substr = ''.join(l[your_index:i])
|
||||
if substr in translate:
|
||||
current_letter = translate[substr]
|
||||
sofars.append(current_letter)
|
||||
print sofars
|
||||
|
||||
MIN_LEN = min(len(k) for k in translate)
|
||||
MAX_LEN = max(len(k) for k in translate)
|
||||
|
||||
letters = [i for i in sys.stdin.readline().strip()]
|
||||
results = []
|
||||
|
||||
mogrificate(letters, 0, results)
|
1
jt-dilema/stdin1.txt
Normal file
1
jt-dilema/stdin1.txt
Normal file
@ -0,0 +1 @@
|
||||
.__..__._..._
|
Loading…
Reference in New Issue
Block a user