def euler(): # set of the digits to use for generating numbers: all the digits except # '1', see related hack digits = list(set(range(10)) - {1}) # number of matches found, only take the second one matches_count = 0 # for each permutation of the digits for digit_permutation in sequence.permutations(digits): # for each truncation in that permutation for base_digits in sequence.right_truncations(digit_permutation): # add '1' at the beginning of the number, because the number # must start with a '1' in order to have the same number of digits # when multiplied by 6 base_digits = [1] + base_digits # the base number which will be multiplied base = int(''.join(str(digit) for digit in base_digits)) # found will stay True if all the multiplications by the FACTORS # have the same digits found = True # for each factor, check if it yields the same digits for factor in FACTORS: found = found and set(str(base)) == set(str(base * factor)) # if it's a valid answer if found: # return the second valid answer found matches_count += 1 if matches_count == 2: return base
def is_truncatable(number): if number < 10: return False for truncation in sequence.left_truncations(str(number)): if not primeutils.is_prime(int(truncation)): return False for truncation in sequence.right_truncations(str(number)): if not primeutils.is_prime(int(truncation)): return False return True