Example #1
0
def is_truncatable_right(n):
    loop_count = len(str(n))
    x = str(n)
    while loop_count != 0:
        if is_prime(int(x)):
            if loop_count > 1:
                x = remove_right(x)
            else:
                return True
        else:
            return False
        loop_count -= 1
Example #2
0
# buffer = []
# factors = remove_one_and_last(get_factors_of_positive_integer(14))
# print(factors)
#
# for f in factors:
#     if is_prime(f):
#         buffer.append(f)
#     else:
#         buffer.extend(remove_one_and_last(get_factors_of_positive_integer(f)))

distinct = 3
streak_limit = 4
consecutive = []
streak = 0
for i in itertools.count(646):
    if is_prime(i):
        consecutive = []
        streak = 0
        continue
    # if i == 650:
    #     break
    factors = remove_one_and_last(get_factors_of_positive_integer(i))
    if len(factors) > distinct:
        print(i, factors)
        consecutive.append(i)
        streak += 1
        if streak == streak_limit:
            break
    else:
        consecutive = []
        streak = 0
Example #3
0
def is_not_prime(n):
    return not is_prime(n)
Example #4
0
 def test_if_600851475143_then_it_must_return_false(self):
     self.assertFalse(leonhard.is_prime(600851475143))
Example #5
0
    num_iter = []
    for j in i:
        num_iter.append(int("".join(j)))
    return num_iter


even = [0, 2, 4, 6, 8]
circular_primes = []
for i in range(1, 101):
    if i == 1:
        continue
    if i == 2:
        circular_primes.append(i)
    if int(str(i)[-1]) in even:
        continue
    if not is_prime(i):
        continue

    num_iter = deque(num_to_iter(i))
    buffer = []
    for j in range(len(num_iter)):
        buffer.append(list(num_iter))
        num_iter.rotate(1)
    circular = iter_to_num(buffer)
    true_circular = list(filter(is_prime, circular))

    if len(circular) == len(true_circular):
        circular_primes.append(i)

    # circular = iter_to_num(list(set(permutations(num_to_iter(i)))))
    # print(i)
Example #6
0
 def test_if_4_then_it_must_return_false(self):
     self.assertFalse(leonhard.is_prime(4))
Example #7
0
 def test_if_7652413_then_it_must_return_true(self):
     self.assertTrue(leonhard.is_prime(7652413))
Example #8
0
 def test_if_2_then_it_must_return_true(self):
     self.assertTrue(leonhard.is_prime(2))
Example #9
0
 def test_if_input_is_string_then_it_must_raise_type_error(self):
     with self.assertRaises(TypeError):
         leonhard.is_prime("test")
Example #10
0
 def test_if_negative_input_then_it_must_raise_value_error(self):
     with self.assertRaises(ValueError):
         leonhard.is_prime(-1)
Example #11
0
from leonhard.leonhard import is_prime
import itertools


def twice_square(n):
    return 2 * (n**2)


for n in itertools.count(1):
    if n % 2 == 0:
        continue
    if not is_prime(n):
        for i in itertools.count(1):
            x = twice_square(i)
            if x < n:
                if is_prime(n - x):
                    # print(f"{n} = {n-x} + (2 x ({i ** 2}))")
                    break
            else:
                print(n)
                break
Example #12
0
# Default fibonacci sequence
# Two terms, starting with 0 and 1
# [0, 1]
print(leonhard.generate_fibonacci_sequence())

# Fibonacci sequence with 5 terms, starting with 0 and 1
# [0, 1, 1, 2, 3]
print(leonhard.generate_fibonacci_sequence(5))

# Fibonacci sequence with 5 terms, starting with 3 and 6
# [3, 6, 9, 15, 24]
print(leonhard.generate_fibonacci_sequence(5, 3, 6))

# 600851475143 is not prime
print(leonhard.is_prime(600851475143))

# 7652413 is prime
print(leonhard.is_prime(7652413))

# Is a Pythagorean triplet
print(leonhard.is_pythagorean_triplet(3, 4, 5))

# Is not a Pythagorean triplet
print(leonhard.is_pythagorean_triplet(1, 2, 3))

# Number of digits is 3
print(leonhard.count_digits(256))

# Collatz sequence
print(leonhard.generate_collatz_sequence(10, []))