noether/py/primes.py

80 lines
2.2 KiB
Python

# Modulo Test
from prbraid.math import *
from prbraid.color import *
import sys
from math import gcd
from time import sleep
PROMPT = '[n]: '
'''
Modify the body of this function, it will be run
against every prime number ascending.
'''
def test_function(p: int, phi: int):
p_color = Color.Green
result_color = Color.Yellow
result = phi / gcd(p, phi) - 1
if result < 0 or not is_prime(result):
p_color = Color.Red
result_color = Color.Red
uprint(p, color=p_color, style=Color.Bold, end=' -> ', flush=False)
uprint(result, color=result_color, flush=True)
sleep(0.1)
def main():
n = -1
while True:
n += 1
# calculate phi of n
phi = totient(n)
# determine if n is prime
prime = n - 1 == phi
if not prime:
continue
# # primitive root values
# proot_v = []
# # primitive root count
# proot_c = 0
# # cumulative sum of primitive root orbits
# prorb_cum = []
# # find all invertible elements (skipped for now)
# for a in range(n):
# orb, ord = orbit(a, n)
# # check if `a` is a primitive root
# proot = (ord + 1 == n)
# proot_c += proot
# if proot:
# proot_v.append(a)
# if not prorb_cum:
# prorb_cum = orb
# else:
# orb_cum(prorb_cum, orb)
# print(a)
# uprint('Cum Orb: ', end='', color=Color.Cyan)
# uprint(f'{prorb_cum}', flush=True)
# prorb_cum_mod = [x % n for x in prorb_cum]
# uprint(f' {prorb_cum_mod}', flush=True)
# uprint('Roots: ', end='', color=Color.Cyan)
# uprint(proot_v, flush=True)
# root_delta = [proot_v[i+1] - proot_v[i] for i in range(proot_c - 1)]
# uprint('Delta: ', end='', color=Color.Cyan)
# uprint(root_delta, flush=True)
# uprint('Roots/Phi: ', end='', color=Color.Cyan)
# uprint(f'{proot_c}/{phi}\n', flush=True)
test_function(n, phi)
if __name__ == '__main__':
try:
main()
except (KeyboardInterrupt, EOFError):
pass