Exemple #1
0
def pandigital_multiples():
    n = 5
    pand_max = 0
    x = 9

    while n > 1:
        seq = list(range(1, n + 1))
        mults = [x * i for i in seq]
        concat_int = int(reduce(lambda x, y: x + y, [str(m) for m in mults]))
        if concat_int > 10**9 - 1:
            n -= 1
        else:
            if is_pandigital(concat_int) and concat_int > pand_max:
                pand_max = concat_int
        x += 1

    return pand_max
def problem_38():
    base = 1
    multipliers = range(1,10)
    possibilities = []
    finished = False
    while not finished:
    # for j in xrange(2):

        for i in xrange(2,10):
            parts = [str(base * m) for m in multipliers[:i]]
            num = reduce(operator.add, parts)
            if len(num) > 9:
                if i == 2:
                    finished = True
                continue
            if utils.is_pandigital(num):
                possibilities.append(int(num))

        base += 1

    return max(possibilities)
def problem_32():

    a = 1
    b = 1
    prod_set = set()
    while(True):
        # a incrementing logic
        b = a
        while(True):
            # b incrementing logic
            if utils.is_pandigital([a, b, a*b]):
                prod_set.add(a*b)

            b += 1
            if len(str(a) + str(b) + str(a*b)) > 9:
                break

        a += 1
        if len(str(a)*2 + str(a*a)) > 9:
            break
    return sum(prod_set)
def problem_38():
    base = 1
    multipliers = range(1, 10)
    possibilities = []
    finished = False
    while not finished:
        # for j in xrange(2):

        for i in xrange(2, 10):
            parts = [str(base * m) for m in multipliers[:i]]
            num = reduce(operator.add, parts)
            if len(num) > 9:
                if i == 2:
                    finished = True
                continue
            if utils.is_pandigital(num):
                possibilities.append(int(num))

        base += 1

    return max(possibilities)
def problem_32():

    a = 1
    b = 1
    prod_set = set()
    while (True):
        # a incrementing logic
        b = a
        while (True):
            # b incrementing logic
            if utils.is_pandigital([a, b, a * b]):
                prod_set.add(a * b)

            b += 1
            if len(str(a) + str(b) + str(a * b)) > 9:
                break

        a += 1
        if len(str(a) * 2 + str(a * a)) > 9:
            break
    return sum(prod_set)