minimum working requirements
This commit is contained in:
parent
c743ca0b85
commit
a168a728ce
4 changed files with 88 additions and 34 deletions
66
m.py
66
m.py
|
|
@ -2,30 +2,72 @@
|
|||
from prbraid.math import *
|
||||
from prbraid.color import *
|
||||
|
||||
import sys
|
||||
|
||||
PROMPT = '[n]: '
|
||||
|
||||
def main():
|
||||
while True:
|
||||
x = None
|
||||
n = None
|
||||
strlen_n = None
|
||||
try:
|
||||
uprint('This is red!', color=Color.Red, end=' ', flush=False)
|
||||
uprint('And this is green!', color=Color.Green, flush=True)
|
||||
x = int(input('[n]: '))
|
||||
uprint(PROMPT, color=Color.Blue, end='')
|
||||
n = input()
|
||||
strlen_n = len(n)
|
||||
n = int(n)
|
||||
except ValueError:
|
||||
continue
|
||||
|
||||
# calculate phi of n
|
||||
phi = totient(n)
|
||||
# determine if n is prime
|
||||
prime = n - 1 == phi
|
||||
# sys.stdout.write('\x1b[1A')
|
||||
# sys.stdout.flush()
|
||||
if prime:
|
||||
uprint('', moveup=1, end='', flush=False)
|
||||
column = len(PROMPT) + strlen_n + 1
|
||||
sys.stdout.write(f'\033[{column}C')
|
||||
uprint('[PRIME]', color=Color.Magenta, style=Color.Bold, flush=True)
|
||||
|
||||
# calculate left padding to align i values
|
||||
lpadded = len(str(x))
|
||||
# lpadded = strlen_n
|
||||
# calculate right padding to align len(orb) values
|
||||
rpadded = len(str(phi))
|
||||
|
||||
# find all invertible elements (skipped for now)
|
||||
for i in range(x):
|
||||
lpad = ' ' * (lpadded - len(str(i)))
|
||||
grp = orbit(i, x)
|
||||
print(f'{lpad}{i} -> {len(grp)} | {grp}')
|
||||
for a in range(n):
|
||||
orb = orbit(a, n)
|
||||
ord = len(orb)
|
||||
|
||||
# check if `a` is a primitive root
|
||||
proot = (ord + 1 == n)
|
||||
|
||||
# calculate padding
|
||||
lpad = ' ' * (strlen_n - len(str(a)))
|
||||
rpad = ' ' * (rpadded - len(str(ord)))
|
||||
# calculate coloring
|
||||
color_a = Color.Red
|
||||
color_ord = None
|
||||
color_orb = None
|
||||
style_ord = None
|
||||
style_orb = None
|
||||
if proot:
|
||||
color_a = Color.Green
|
||||
color_ord = Color.Yellow
|
||||
color_orb = Color.Green
|
||||
style_ord = Color.Bold
|
||||
style_orb = Color.Bold
|
||||
|
||||
uprint(f'{lpad}{a}', color=color_a, style=Color.Bold, end=' ', flush=False)
|
||||
uprint(f'->', end=' ', flush=False)
|
||||
uprint(f'{ord}{rpad}', color=color_ord, style=style_ord, end=' ', flush=False)
|
||||
uprint(f'|', end=' ', flush=False)
|
||||
uprint(f'{orb}', color=color_orb, style=style_orb, flush=True)
|
||||
print() # empty new line
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
main()
|
||||
except (KeyboardInterrupt, EOFError):
|
||||
pass
|
||||
|
||||
|
||||
pass
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue