Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Parity Bit Generator by lukasz.bogaczynski
def checkio(encoded_message):
for index, number in enumerate(encoded_message):
number_in_binary = "{0:b}".format(number)
occurrance_of_one = number_in_binary.count("1")
if occurrance_of_one % 2 == 0:
encoded_message[index] = chr(int(number_in_binary[: len(number_in_binary) - 1],2))
else:
encoded_message[index] = None
return ''.join(list(filter(lambda x : x is not None, encoded_message)))
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert checkio([135, 134, 124, 233,
209, 81, 42, 202,
198, 194, 229, 215,
230, 146, 28, 210,
145, 137, 222, 158,
49, 81, 214, 157]) == "Checkio"
assert checkio([144, 100, 200, 202,
216, 152, 164, 88,
216, 222, 65, 218,
175, 217, 248, 222,
171, 228, 216, 205,
254, 201, 193, 220]) == "Hello World"
Oct. 21, 2017