Skip to content

Instantly share code, notes, and snippets.

@erdem
Last active November 30, 2015 01:25
Show Gist options
  • Save erdem/7479693d70c581a60e7f to your computer and use it in GitHub Desktop.
Save erdem/7479693d70c581a60e7f to your computer and use it in GitHub Desktop.
Codingame Chuck Norris keyboard puzzle
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