Mystery längs 26:an #213

Mystery längs 26:an #213

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, 113379904):  # 1.000.000 i bas 22
    base22 = number2base(i, 22)
    if base22 == base22[::-1]:
        j += 1
        summa += i
        print(str(j) + " " + base22)
print("Antal: " + str(j) + " eller " + number2base(j, 22) + " i bas 22")
print("Summa: " + str(summa) + " eller " + number2base(summa, 22) + " i bas 22")