curriculum/challenges/english/blocks/daily-coding-challenges-python/69a890af247de743333bd4cc.md
Given a 6x6 matrix (array of arrays), representing a QR code, return the string of binary data in the code.
1's (orientation markers) in the bottom-left, top-left, and top-right corners.For example, given:
[
"110011",
"110011",
"000000",
"000000",
"110000",
"110001"
]
or given the same code with a different orientation:
[
"110011",
"110011",
"000000",
"000000",
"000011",
"100011"
]
Return "000000000000000000000001", all the binary data excluding the three 2x2 orientation markers.
decode_qr(["110011", "110011", "000000", "000000", "110000", "110001"]) should return "000000000000000000000001".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(decode_qr(["110011", "110011", "000000", "000000", "110000", "110001"]), "000000000000000000000001")`)
}})
decode_qr(["100011", "000011", "000000", "000000", "110011", "110011"]) should return "000000000000000000000001".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(decode_qr(["100011", "000011", "000000", "000000", "110011", "110011"]), "000000000000000000000001")`)
}})
decode_qr(["110011", "111111", "010000", "110000", "110011", "110100"]) should return "001101000011000000110100".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(decode_qr(["110011", "111111", "010000", "110000", "110011", "110100"]), "001101000011000000110100")`)
}})
decode_qr(["011011", "101011", "101000", "100010", "110011", "111011"]) should return "010001000100010101010110".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(decode_qr(["011011", "101011", "101000", "100010", "110011", "111011"]), "010001000100010101010110")`)
}})
decode_qr(["111100", "110001", "100011", "001101", "110011", "110011"]) should return "010000100100100101001110".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(decode_qr(["111100", "110001", "100011", "001101", "110011", "110011"]), "010000100100100101001110")`)
}})
def decode_qr(qr_code):
return qr_code
def is_oriented(code):
marker_indices = [
(0, 0),
(0, 1),
(0, 4),
(0, 5),
(1, 0),
(1, 1),
(1, 4),
(1, 5),
(4, 0),
(4, 1),
(5, 0),
(5, 1)
]
for row, col in marker_indices:
if code[row][col] != '1':
return False
return True
def rotate(code):
new_code = ['', '', '', '', '', '']
for i in range(6):
for j in range(5, -1, -1):
new_code[i] += code[j][i]
return new_code
def get_data(code):
data = ''
data += code[0][2:4]
data += code[1][2:4]
data += code[2]
data += code[3]
data += code[4][2:]
data += code[5][2:]
return data
def decode_qr(qr_code):
code = qr_code[:]
while not is_oriented(code):
code = rotate(code)
return get_data(code)