def p50(): primelist = list(primes(4000)) for x in range(1,200): for y in range(x,-1,-1): s = sum(primelist[y:len(primelist)-(x-y)]) if is_prime(s): return s
def p51(): primelist = [p for p in primes(1000000) if p > 100001] for prime in primelist: for number_family in number_familes(prime): prime_family = [n for n in number_family if is_prime(n) and len(str(n)) == len(str(prime))] if len(prime_family) == 8 and prime in prime_family: print prime return
def get_combs(): seed = {3: set([3]), 7: set([7]), 9: set([9]), 13: set([13]), 17: set([17]), 19: set([19]), 23: set([23]), 29: set([29]), 31: set([31]), 37: set([37])} print "done prime gen" for prime in primes(10000)[1:]: print seed for key in seed.keys(): print key gprime = True for pr in seed[key]: print pr if not good_pair(prime, pr): gprime = False break if gprime: seed[key].add(prime) if good_pair(prime, key): seed.setdefault(prime, set()).add(pr) print seed
) # so that this statement incorrectly raises a RuntimeError exception if __name__ == '__main__': # Test differences; you can add your own test cases print('Testing differences') for i in differences('3.14159265', '3x14129285'): print(i, end=' ') print() for i in differences(hide('3.14159265'), hide('3x14129285')): print(i, end=' ') print() for i in differences(primes(), hide([2, 3, 1, 7, 11, 1, 17, 19, 1, 29])): print(i, end=' ') print('\n') for i in differences(hide([2, 3, 1, 7, 11, 1, 17, 19, 1, 29]), primes()): print(i, end=' ') print('\n') # Test once_in_a_row; you can add your own test cases print('\nTesting once_in_a_row') for i in once_in_a_row([None, None, 1, 2, None]): print(i, end='') print() for i in once_in_a_row(hide('abcccaaabddeee')): print(i, end='')
from helpers import primes print primes(10001)[-1]
from itertools import permutations from helpers import test, primes PRIMES = primes(7) def check_sub_string_divisibility(n): n = str(n) for i in range(1, 8): sub_string = int(n[i:i + 3]) if sub_string % PRIMES[i - 1] != 0: return False return True def find_sub_string_divisibility(): digits = [str(d) for d in range(10)] numbers = [] for arrangement in permutations(digits): if arrangement[0] == 0: continue n = int(''.join(arrangement)) if check_sub_string_divisibility(n): numbers.append(n)
print(' command raised exception') if __name__ == '__main__': # Test differences; you can add your own test cases print('Testing differences') for i in differences('3.14159265', '3x14129285'): print(i, end=' ') print() for i in differences(hide('3.14159265'), hide('3x14129285')): print(i, end=' ') print() for i in differences(primes(), hide([2, 3, 1, 7, 11, 1, 17, 19, 1, 29])): print(i, end=' ') print('\n') # Test once_in_a_row; you can add your own test cases print('\nTesting once_in_a_row') for i in once_in_a_row('abcccaaabddeee'): print(i, end='') print() for i in once_in_a_row(hide('abcccaaabddeee')): print(i, end='') print('\n') # Test in_between; you can add your own test cases print('\nTesting in_between')
if __name__ == '__main__': # Test running_count; you can add your own test cases print('\nTesting running_count') for i in running_count('bananastand', lambda x: x in 'aeiou'): # is vowel print(i, end=' ') print() for i in running_count(hide('bananastand'), lambda x: x in 'aeiou'): # is vowel print(i, end=' ') print() print(nth(running_count(primes(), lambda x: x % 10 == 3), 1000)) # Test stop_when; you can add your own test cases print('\nTesting stop_when') for c in stop_when('abcdefghijk', lambda x: x >= 'd'): print(c, end='') print() for c in stop_when(hide('abcdefghijk'), lambda x: x >= 'd'): print(c, end='') print('\n') print(nth(stop_when(primes(), lambda x: x > 100000), 100)) # Test group_when; you can add your own test cases print('\nTesting yield_and_skip')