def main(x): pandigitals = number_permutations.main(x) #gets all permutations of entered digits pandigitals = sorted(pandigitals) #sorts the pandigital permutations (smallest to largest) pandigitals = pandigitals[::-1] #reverses the order so the pandigitals are largest to smallest prime = 0 #will store eventual answer index = 0 #placeholder index while prime == 0: #continues until a prime is found print(index) if check_prime.main(pandigitals[index]) == 1: #checks if number is prime prime = pandigitals[index] #stores prime if found else: #if number checked is not prime, increments index for search index += 1 return prime
def main(): import number_permutations permutations = number_permutations.main(123456789) #imports function and then uses it to find a list of all 1-9 pandigital sequences digits_list = ['1', '2', '3', '4', '5', '6', '7', '8', '9'] #stores the digits one through nine, each as a string, for use in splitting the pandigital strings later good_trios = [] for perm in permutations: #performs loop for each permuation for i in digits_list: parts_list = str(perm).partition(str(i)) #splits permutation at digit i parts_list = [parts_list[0], (parts_list[1] + parts_list[2])] #combines the last two entries (i and whatever was after it) into a single entry if parts_list[0] != '' and parts_list[1] != '': #ignores the split if either part ends up empty for j in digits_list: #must split at a different digit than before if j != i: splits = parts_list[1].partition(str(j)) #splits the second part at digit j trio = [ parts_list[0], splits[0], (splits[1] + splits[2]) ] #combines the last two entries (j and whatever was after it) into a single entry if trio[0] != '' and trio[1] != '' and trio[2] != '': #ignores further actions if any part ends up empty if int(trio[0]) * int(trio[1]) == int(trio[2]): #stores trio if it meets the criteria good_trios.append(trio) #print(trio) #TEST return good_trios
def main(p): #finds first number with p cube permutations i = 100 # need to start search with at least 3-digit number desired_number = 0 #will hold number once found, used as check in while loop while desired_number == 0: #loop continues until suitable number found #TEST print(i) q = i ** 3 #finds cube of number cube_permutations = 0 #will be used to count number of permutations that are cubes permute_list = number_permutations.main(q) #gets the permutations of i^3 cube_list = [] #for testing purposes, stores list of cube permutations for j in permute_list: #checks if j is a cube, if it is adds one to the number of found cube permutations cube_num = is_cube(j) cube_permutations += cube_num if cube_num == 1: #for testing purposes, stores list of cube permutations cube_list.append(j) if cube_permutations == p: #defines required criteria desired_number = q else: i += 1 #increments i if desired number has not been found return [i,desired_number,cube_list]
def main(): #solves given problem permutations = number_permutations.main(1234567890) #finds all 0-9 pandigital numbers num_with_prop = [] #will store all numbers with desired property for i in permutations: if check_property(i) == 1: num_with_prop.append(i) return sum(num_with_prop)
def main(): #solves defined problem by searching through pairs of primes primes = find_primes_below.main(10**4) #arbitrarily chosen cap for primes based on problem cap of 10^7 stored_num = [0, 0] #will store highest totient / n as well as the number n for i in primes: for j in primes: n = i * j #since we are searching for numbers with 2 prime factors if n < (10**7): #requirement for max n p_list = [i, j] tot_div_n = totient_over_n(p_list) #calculates totient/n using above function totient = tot_div_n * n #calculates the totient if totient in number_permutations.main(n): #i.e. if φ(n) is a permutation of n if tot_div_n > stored_num[0]: #i.e. if higher than last previous highest totient/n found stored_num = [tot_div_n, n] #stores numbers to be compared to or for answer if best #TEST print('i=', i, 'j=', j, 'stored_num=', stored_num) #TEST return stored_num
import find_primes_below primes_list = find_primes_below.main(10000) #gets list of all primes below 10000 (4 digits or less) import number_permutations #number_permutations.main(x) returns a list of all permutations of x matches_criteria=[] #will hold all numbers meeting desired criteria for i in primes_list: #NOT NECESSASRY AND MISSES SOME## if len("".join(set(str(i)))) == 4: #checks that there are no duplicate digits in i permutations = number_permutations.main(i) #gets permutations of i prime_permutations = [] #starts list of permutations that are prime for j in permutations: #loop adds any prime permutations to list if j in primes_list: prime_permutations.append(j) for k in range (1,5000): #arithmetic difference between primes must be at least in this range if (i + k) in prime_permutations and (i + (2*k)) in prime_permutations: #checks if there is a 3-tuple of primes matches_criteria.append([i,i+k,i+2*k]) #adds them to list of tuples matching criteria