74 lines
1.8 KiB
Python
74 lines
1.8 KiB
Python
def solution(s):
|
|
result = ""
|
|
for c in s:
|
|
result += to_braille(c)
|
|
return result
|
|
|
|
def to_braille(c):
|
|
if c == ' ':
|
|
return "000000"
|
|
if c == 'a':
|
|
return "100000"
|
|
if c == 'b':
|
|
return "110000"
|
|
if c == 'c':
|
|
return "100100"
|
|
if c == 'd':
|
|
return "100110"
|
|
if c == 'e':
|
|
return "100010"
|
|
if c == 'f':
|
|
return "110100"
|
|
if c == 'g':
|
|
return "110110"
|
|
if c == 'h':
|
|
return "110010"
|
|
if c == 'i':
|
|
return "010100"
|
|
if c == 'j':
|
|
return "010110"
|
|
if c == 'k':
|
|
return "101000"
|
|
if c == 'l':
|
|
return "111000"
|
|
if c == 'm':
|
|
return "101100"
|
|
if c == 'n':
|
|
return "101110"
|
|
if c == 'o':
|
|
return "101010"
|
|
if c == 'p':
|
|
return "111100"
|
|
if c == 'q':
|
|
return "111110"
|
|
if c == 'r':
|
|
return "111010"
|
|
if c == 's':
|
|
return "011100"
|
|
if c == 't':
|
|
return "011110"
|
|
if c == 'u':
|
|
return "101001"
|
|
if c == 'v':
|
|
return "111001"
|
|
if c == 'w':
|
|
return "010111"
|
|
if c == 'x':
|
|
return "101101"
|
|
if c == 'y':
|
|
return "101111"
|
|
if c == 'z':
|
|
return "101011"
|
|
if ord('A') <= ord(c):
|
|
return "000001" + to_braille(chr(ord(c) - ord('A') + ord('a')))
|
|
|
|
tests = [
|
|
("code", "100100101010100110100010"),
|
|
("Braille", "000001110000111010100000010100111000111000100010"),
|
|
("The quick brown fox jumps over the lazy dog", "000001011110110010100010000000111110101001010100100100101000000000110000111010101010010111101110000000110100101010101101000000010110101001101100111100011100000000101010111001100010111010000000011110110010100010000000111000100000101011101111000000100110101010110110"),
|
|
]
|
|
|
|
for i, o in tests:
|
|
result = solution(i)
|
|
print (i, result == o, result, o)
|