Mystery längs 26:an #228

Mystery längs 26:an #228

def number2base(x, base):
    digs = "0123456789abcdefghijklmnopqrstuvwxyz"
    if x == 0:
        return digs[0]
    digits = []
    while x:
        digits.append(digs[x % base])
        x = x // base
    digits.reverse()
    return ''.join(digits)


j = 0
summa = 0
for i in range(0, 4294967296):
    if number2base(i, 2) == number2base(i, 2)[::-1]:
        j += 1
        summa += i
        print(str(j) + ": " + number2base(i, 2))
print("Antal: " + str(j))
print("Summa: " + str(summa))
print("Antal i bas 2: " + number2base(j, 2))
print("Summa i bas 2: " + number2base(summa, 2))