Ejemplo n.º 1
0
def main():
    """ challenge043 """
    source = "0123456789"

    return sum([int(n) for n in permutate(source)
                if int(n) >= 1000000000 and
                int(n[7:10]) % 17 == 0 and
                int(n[6:9]) % 13 == 0 and
                int(n[5:8]) % 11 == 0 and
                int(n[4:7]) % 7 == 0 and
                int(n[3:6]) % 5 == 0 and
                int(n[2:5]) % 3 == 0 and
                int(n[1:4]) % 2 == 0])
Ejemplo n.º 2
0
def main():
    """ challenge041 """
    # loop through number of digits
    highest = 0
    for number_size in [4, 7]:
        chars = "".join([str(c) for c in range(1, number_size + 1)])
        for potential in [int(p)
                          for p in permutate(chars)
                          if is_prime(int(p))]:
            # if potential > highest:
            # Potential is always higher in this scenario.
            highest = potential

    return highest
Ejemplo n.º 3
0
def main():
    """ challenge032 """
    source = "123456789"
    products = []
    for potential in [int(p) for p in permutate(source)]:
        # * can be after 1, 2, 3, 4
        # = can only be between 5 and 6
        third = potential % 10**4
        for i in range(1, 3):
            first = potential // 10**(9 - i)
            second = (potential // 10**(4)) % 10**(5 - i)
            product = first * second
            if product == third:
                products.append(third)

    return sum(set(products))
Ejemplo n.º 4
0
def test_permutate(input, expected):
    actual = set(permutate(input))
    expect(actual).to.eq(expected)
Ejemplo n.º 5
0
def main():
    """ challenge024 """
    number = "0123456789"
    return int(list(islice(permutate(number), 999999, 1000000))[0])