Last active
November 30, 2015 01:25
-
-
Save erdem/7479693d70c581a60e7f to your computer and use it in GitHub Desktop.
Codingame Chuck Norris keyboard puzzle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
message = raw_input() | |
binaries = "" | |
for c in message: # converting all inputs to 7 bit | |
bnr = format(ord(c), 'b') | |
if len(bnr) < 7: | |
bnr = "0"*(7-len(bnr)) + bnr | |
binaries += bnr | |
binary_value = "" | |
for i, b in enumerate(binaries): | |
if b == "0": | |
if i > 0 and binaries[i-1] == binaries[i]: | |
binary_value += "0" | |
else: | |
if i > 0: | |
binary_value += " 00 0" | |
else: | |
binary_value += "00 0" | |
if b == "1": | |
if i > 0 and binaries[i-1] == binaries[i]: | |
binary_value += "0" | |
else: | |
if i > 0: | |
binary_value += " 0 0" | |
else: | |
binary_value += "0 0" | |
print binary_value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment