From e24fc282579201d7d5fdcfbf8a401ca34645709b Mon Sep 17 00:00:00 2001 From: Seongbeom Park Date: Wed, 11 May 2022 13:44:07 +0900 Subject: [PATCH] finish extra/braille-translation Submitting solution... Submission: SUCCESSFUL. Completed in: 18 mins, 46 secs. --- README.md | 5 ++ extra/braille-translation/solution.py | 73 +++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 extra/braille-translation/solution.py diff --git a/README.md b/README.md index d09ff9a..9cf7eaa 100644 --- a/README.md +++ b/README.md @@ -117,3 +117,8 @@ CFcSBwgCCBoHRhkKU1cGAA4AGU5YQR5THBwNFwoGGAxTQQMQVBUSBg4EAAwQRhUQVBUHFAQTGRpT QQM ### minion-work-assignments * Completed in: 7 mins, 40 secs. + +### braille-translation +* Completed in: 18 mins, 46 secs. +* Reference + * [The Braille Alphabet](https://www.pharmabraille.com/pharmaceutical-braille/the-braille-alphabet/) diff --git a/extra/braille-translation/solution.py b/extra/braille-translation/solution.py new file mode 100644 index 0000000..1c38490 --- /dev/null +++ b/extra/braille-translation/solution.py @@ -0,0 +1,73 @@ +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)