Daily Coding Challenge - QR Decoder

Tell us what’s happening:

QR-code decoder: All other tests passed except this last one. Test no. 5. Test says, the function should return; “010000100100100101001110” while my function returns; “000000110110001100011100”. I couldn’t determine the issue here.

Your code so far

def decode_qr(qr_code):
    b_data = ""

    # to see if given qr_code is upside down.
    v_dir = None
    if (qr_code[0][:2] == '11' and qr_code[0][-2:] == '11') and (qr_code[1][:2] == '11' and qr_code[1][-2:] == '11'):
        v_dir = 1
    else:
        v_dir = -1
    
    # to check if given qr_code is horizontally flipped.
    h_dir = None
    if v_dir == 1:
        if qr_code[-1][:2] == '11':
            h_dir = 1
        else:
            h_dir = -1
    else:
        if qr_code[0][:2] == '11':
            h_dir = 1
        else:
            h_dir = -1
    
    #print('vertical:', v_dir)
    #print('horizontal:', h_dir)

    # Extracts binary data from qr_code, excluding markers
    for i, row in enumerate(qr_code[::v_dir], 1):
        row = row[::h_dir]
        print(row)

        if i == 1 or i == 2:
            b_data += row[2:4]
            #print('1, 2', row[2:4])
        elif i == 5 or i == 6:
            b_data += row[2:]
            #print('5, 6', row[2:])
        else:
            #print('3, 4', row)
            b_data += row


    print('Binary Data:')
    return b_data

# Input given in test no. 
sample = [
    "111100", 
    "110001", 
    "100011", 
    "001101", 
    "110011", 
    "110011"]
print(decode_qr(sample))

# Sample with correct orientation will be:
"""
    "110011",
    "110011",
    "001101",
    "100011",
    "110001",
    "111100"
"""

# Output: 000000110110001100011100
# Test says, it should be: 010000100100100101001110
# While all the other tests passed with no problem.

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36

Challenge Information:

Daily Coding Challenge - QR Decoder

https://www.freecodecamp.org/learn/daily-coding-challenge/2026-03-21

It seems that flipping the qr code might not work for all cases, to get the correctly rotated code.

No. The sample with correct orientation (rotated 90 degrees clockwise) should be:

"""
”110111”,
”110011”,
”001001”,
”001001”,
“110100”,
”111110”
"""