Ejemplo n.º 1
0
def euler():
    middle = math.ceil(math.sqrt(HIGHEST_N))
    for p in range(middle, 0, -1):
        if prime.is_prime(p):
            for q in range(middle + 1, math.ceil((10 ** 7) / p)):
                if prime.is_prime(q):
                    n = p * q
                    t = discreet.totient(n)
                    if sequence.is_permutation(str(n), str(t)):
                        return n
Ejemplo n.º 2
0
def euler():
    for n in range(346, 6000):
        # number of cubes that are permutations of n^3
        cube_permutations = 0
        digits = str(n * n * n)
        maximum = maximum_for(digits)
        # for each number from n to maximum (see maximum_for()), check if its
        # cube is a permutation of n
        for m in range(n, maximum):
            cube = m * m * m
            if is_permutation(str(cube), digits):
                cube_permutations += 1
        # return it if it has the right number of permutations
        if cube_permutations == 5:
            return n ** 3
Ejemplo n.º 3
0
def is_int_permutation(x, y):
    """Return True iff two integers are permutations of eachother's digits."""
    return sequence.is_permutation(list(str(x)), list(str(y)))