Exemple #1
0
def f1(n):
    """Single digit ms. O(terrible)"""
    low = 10**(n - 1) - 1
    hi = 10**n - 1
    best = 0
    for x in range(hi, low, -1):
        for y in range(x, low, -1):
            prod = x*y
            if prod < best:
                # if prod < best when y is hi, we are done
                # if y is smaller, maybe a new x will work better
                if y == x:
                    return best
                else:
                    break
            if is_palin(prod):
                if prod > best:
                    best = prod
Exemple #2
0
def f(n):
    return sum([a for a in range(n) if is_palin(a) and is_bin_palin(a)])
Exemple #3
0
def f0(n):
    """Nearly a second for 3"""
    rng = range(10**(n - 1), 10**n)
    return max([x*y for x in rng for y in rng if is_palin(x*y)])