示例#1
0
def eighty_nine(m):
    n = m
    while n != 1 and n != 89 and n not in mem:
        n = reduce(lambda accu, v: accu + to_digit(v) * to_digit(v), str(n), 0)
    if m < 1000:
        if n in mem:
            mem[m] = mem[n]
        else:
            mem[m] = n == 89
        return mem[m]
    else:
        return mem[n]
示例#2
0
from strings import to_digit

s = ''
i = 1
while len(s) < 1000000:
    s += str(i)
    i += 1

print to_digit(s[0]) * to_digit(s[9]) * to_digit(s[99]) * to_digit(s[999]) * to_digit(s[9999]) * \
      to_digit(s[99999]) * to_digit(s[999999])
示例#3
0
from strings import to_digit, read_split

names = read_split('p022_names.txt')
names.sort()

s = 0
for i, n in enumerate(names):
    score = reduce(lambda acc, x: acc + to_digit(x, '@'), n[1:-1], 0)
    s += (i + 1) * score

print s
示例#4
0
from strings import to_digit
from maths import factorial

m = 0
for n in xrange(3, 7 * factorial(9)):
    s = 0
    for c in str(n):
        s += factorial(to_digit(c))
    if s == n: m += s

print m
示例#5
0
def facsum(n):
    return reduce(lambda acc, v: acc + factorial(to_digit(v)), str(n), 0)
示例#6
0
from strings import to_digit

ss = 0
for n in xrange(10, 6 * pow(9, 5)):
    s = 0
    for c in str(n):
        s += pow(to_digit(c), 5)
    if s == n: ss += s

print ss
示例#7
0
def digits(n):
    d = [0] * 10
    s = str(n)
    for c in s:
        d[to_digit(c)] += 1
    return d
示例#8
0
from strings import to_digit, read_split

tri = []
for n in xrange(0, 20):
    tri.append(n * (n + 1) / 2)

words = read_split('p042_words.txt')

tw = 0
for word in words:
    s = 0
    for w in word[1:-1]:
        s += to_digit(w, '@')
    for t in tri:
        if s == t: tw += 1

print tw
示例#9
0
from strings import to_digit
from maths import max

s = '7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450'

l = 13
m = 0
for i in xrange(0, len(s) - l):
    v = 1
    for j in xrange(i, i + l):
        v *= to_digit(s[j])
    m = max(m, v)

print m