Last active
October 18, 2022 13:48
-
-
Save CodeByAidan/6207d487c7208bdf1f288f07ac64699f to your computer and use it in GitHub Desktop.
6 kyu hard problem (imo 4kyu) https://www.codewars.com/kata/5ef9c85dc41b4e000f9a645f/train/python
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
positions = [ | |
(20, 18), | |
(19, 18), | |
(20, 17), | |
(19, 17), | |
(20, 16), | |
(19, 16), | |
(20, 15), | |
(19, 15), | |
(20, 14), | |
(19, 14), | |
(20, 13), | |
(19, 13), | |
(20, 12), | |
(19, 12), | |
(20, 11), | |
(19, 11), | |
(20, 10), | |
(19, 10), | |
(20, 9), | |
(19, 9), | |
(18, 9), | |
(17, 9), | |
(18, 10), | |
(17, 10), | |
(18, 11), | |
(17, 11), | |
(18, 12), | |
(17, 12), | |
(18, 13), | |
(17, 13), | |
(18, 14), | |
(17, 14), | |
(18, 15), | |
(17, 15), | |
(18, 16), | |
(17, 16), | |
(18, 17), | |
(17, 17), | |
(18, 18), | |
(17, 18), | |
(18, 19), | |
(17, 19), | |
(18, 20), | |
(17, 20), | |
(16, 20), | |
(15, 20), | |
(16, 19), | |
(15, 19), | |
(16, 18), | |
(15, 18), | |
(16, 17), | |
(15, 17), | |
(16, 16), | |
(15, 16), | |
(16, 15), | |
(15, 15), | |
(16, 14), | |
(15, 14), | |
(16, 13), | |
(15, 13), | |
(16, 12), | |
(15, 12), | |
(16, 11), | |
(15, 11), | |
(16, 10), | |
(15, 10), | |
(16, 9), | |
(15, 9), | |
(14, 9), | |
(13, 9), | |
(14, 10), | |
(13, 10), | |
] | |
def scanner(qrcode): | |
bits = "".join( | |
map(lambda pos: str(unmask(qrcode[pos[1]][pos[0]], pos[0], pos[1])), positions) | |
) | |
length = int(bits[0:8], 2) | |
chars = [ | |
chr(int(bits[8:16], 2)), | |
chr(int(bits[16:24], 2)), | |
chr(int(bits[24:32], 2)), | |
chr(int(bits[32:40], 2)), | |
chr(int(bits[40:48], 2)), | |
chr(int(bits[48:56], 2)), | |
chr(int(bits[56:64], 2)), | |
chr(int(bits[64:72], 2)), | |
] | |
print(length) | |
print(chars) | |
return "".join(chars[0:length]) | |
def unmask(bit, x, y): | |
return invert(bit) if ((x + y) % 2) == 0 else bit | |
def invert(bit): | |
return 0 if bit == 1 else 1 | |
""" | |
[ 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1 ] | |
[ 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1 ] | |
[ 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1 ] | |
[ 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1 ] | |
[ 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1 ] | |
[ 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1 ] | |
[ 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1 ] | |
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] | |
[ 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 ] | |
[ 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1 ] | |
[ 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1 ] | |
[ 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0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