Problem p03104 (python)

Fixed submission:
def convert_binary(n):
    if n == 0:
        return '0'
    s = []
    while True:
        s.append(str(n % 2))
        n = int(n / 2)
        if n == 0:
            break
    return ''.join(s)[::-1]
   
def calc_xor(b1, b2):
    maxlen = max(len(b1), len(b2))
    b1 = '0' * (maxlen - len(b1)) + b1
    b2 = '0' * (maxlen - len(b2)) + b2
    s = ''
    for i in range(maxlen):
        if (int(b1[i]) + int(b2[i])) % 2 == 1:
            s += '1'
        else:
            s += '0'
    return s
   
def convert_decimal(binary):
    n = 0
    i = 0
    for b in binary[::-1]:
        n += (2 ** i) * int(b)
        i += 1
    return n
 
def calc_xor_from_zero(n):
    if (n+1) % 2 == 0:
        count_pair = int((n+1) / 2)
        if count_pair % 2 == 0:
            return '0'
        else:
            return '1'
    else:
        count_pair = int((n+1) / 2)
        if count_pair % 2 == 0:
            return calc_xor('0', convert_binary(n))
        else:
            return calc_xor('1', convert_binary(n))
    
A, B = list(map(int, input().split(' ')))
 
print(convert_decimal(calc_xor(calc_xor_from_zero(A-1), calc_xor_from_zero(B))))

Buggy submission (verdict: Runtime Error):
def convert_binary(n):
    if n == 0:
        return '0'
    s = []
    while True:
        s.append(str(n % 2))
        n = int(n / 2)
        if n == 0:
            break
    return ''.join(s)[::-1]

def calc_xor(bs):
    maxlen = max([len(b) for b in bs])
    for i in range(len(bs)):
        bs[i] = '0' * (maxlen - len(bs[i])) + bs[i]
    s = ''
    for i in range(maxlen):
        if (sum([int(b[i]) for b in bs])) % 2 == 1:
            s += '1'
        else:
            s += '0'
    return s

def convert_decimal(binary):
    n = 0
    i = 0
    for b in binary[::-1]:
        n += (2 ** i) * int(b)
        i += 1
    return n
  
A, B = list(map(int, input().split(' ')))

print(convert_decimal(calc_xor([convert_binary(i) for i in list(range(A, B + 1))])))

Buggy submission (verdict: Runtime Error):
def convert_binary(n):
    s = []
    while True:
        s.append(str(n % 2))
        n = int(n / 2)
        if n == 0:
            break
    return ''.join(s)[::-1]
 
def calc_xor(bs):
    maxlen = max([len(b) for b in bs])
    for i in range(len(bs)):
        bs[i] = '0' * (maxlen - len(bs[i])) + bs[i]
    s = ''
    for i in range(maxlen):
        if (sum([int(b[i]) for b in bs])) % 2 == 1:
            s += '1'
        else:
            s += '0'
    return s
 
def convert_decimal(binary):
    n = 0
    i = 0
    for b in binary[::-1]:
        n += (2 ** i) * int(b)
        i += 1
    return n
  
A, B = list(map(int, input().split(' ')))
 
print(convert_decimal(calc_xor([convert_binary(i) for i in list(range(A, B + 1))])))

Buggy submission (verdict: Runtime Error):
def convert_binary(n):
    s = []
    while True:
        s.append(str(n % 2))
        n = int(n / 2)
        if n == 0:
            break
    return ''.join(s)[::-1]

def calc_xor(bs):
    maxlen = max([len(b) for b in bs])
    for i in range(len(bs)):
        bs[i] = '0' * (maxlen - len(bs[i])) + bs[i]
    s = ''
    for i in range(maxlen):
        if (sum([int(b[i]) for b in bs])) % 2 == 1:
            s += '1'
        else:
            s += '0'
    return s

def convert_decimal(binary):
    n = 0
    for i, b in enumerate(binary[::-1]):
        n += (2 ** i) * int(b)
    return n
  
A, B = list(map(int, input().split(' ')))

print(convert_decimal(calc_xor([convert_binary(i) for i in list(range(A, B + 1))])))