Skip to content
Snippets Groups Projects
work.py 851 B
Newer Older
Guilhem Saurel's avatar
Guilhem Saurel committed
#!/usr/bin/env python3
"""Hard work here. Not efficient, but hard."""

Guilhem Saurel's avatar
Guilhem Saurel committed
from typing import Tuple

import pinocchio as pin  # type: ignore

Guilhem Saurel's avatar
Guilhem Saurel committed

def is_prime(number: int) -> bool:
    """Check if a number is prime."""
    return not any(number % i == 0 for i in range(2, number))


Guilhem Saurel's avatar
Guilhem Saurel committed
def find_prime(goal: int = 10, verbose: bool = False) -> Tuple[int, int]:
Guilhem Saurel's avatar
Guilhem Saurel committed
    """Find the goal-th prime number."""
    found = 0
    i = 1  # let's enumerate all numbers
    while found < goal:  # until we have enough prime ones.
        i += 1
        if is_prime(i):
            found += 1
            if verbose:
                print(f'the prime number n°{found} is {i}')
Guilhem Saurel's avatar
Guilhem Saurel committed
    n = pin.Quaternion(i, i, i, i).norm()
    print(f"the norm of a quaternion with {i} as all members is {n}")
    return i, n
Guilhem Saurel's avatar
Guilhem Saurel committed


if __name__ == '__main__':
    print(find_prime(50, verbose=True))
Guilhem Saurel's avatar
Guilhem Saurel committed