def is_strong_harshad(n): """ Determine if n / (sum of digits of n) is prime :param n: :return: """ sum_digits = euler.sum_digits(n) return n % sum_digits == 0 and euler.is_prime(n / sum_digits)
def solve(max_value): strong_right_truncatable_harshad_primes = [] for right_truncatable in right_truncatable_generator(): # for each right truncatable number, figure out if it is strong, # prime. If so add to sum if is_strong_harshad(right_truncatable): for new_digit in xrange(10): to_test = right_truncatable * 10 + new_digit if euler.is_prime(to_test): strong_right_truncatable_harshad_primes.append(to_test) if to_test > max_value: return sum(strong_right_truncatable_harshad_primes) return sum(strong_right_truncatable_harshad_primes)