def truncatable_prime(num): digit = solutions.get_digits(num) divisor = 1 while num / divisor: val = num / divisor if not solutions.is_prime(val) or val == 1: return False val = num % divisor if val == 1: return False elif val > 0 and not solutions.is_prime(val): return False divisor *= 10 return True
def sum_of_all_amicable_numbers(limit): """ >>> sum_of_all_amicable_numbers(10000) 31626 """ items = [] for num in range(1, limit): if num in items or solutions.is_prime(num): continue result = get_amicable_pair(num) if result: a, b = result if a not in items: items.append(a) if b not in items: items.append(b) return sum(items)
def test_is_prime(self): self.assertFalse(solutions.is_prime(1)) self.assertTrue(solutions.is_prime(2)) self.assertFalse(solutions.is_prime(8)) self.assertTrue(solutions.is_prime(11)) self.assertFalse(solutions.is_prime(-10))
def is_circular_prime(num): for item in get_circular_digits(num): if not solutions.is_prime(list_to_num(item)): return False return True