minimum working requirements
This commit is contained in:
parent
c743ca0b85
commit
a168a728ce
4 changed files with 88 additions and 34 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
__pycache__/
|
||||
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
|
||||
|
|
|
|||
0
prbraid/__init__.py
Normal file
0
prbraid/__init__.py
Normal file
|
|
@ -1,36 +1,38 @@
|
|||
from enum import Enum
|
||||
from typing import Optional
|
||||
|
||||
class Color(Enum):
|
||||
Black = 0
|
||||
Red = 1
|
||||
Green = 2
|
||||
Yellow = 3
|
||||
Blue = 4
|
||||
Magenta = 5
|
||||
Cyan = 6
|
||||
White = 7
|
||||
Reset = 0
|
||||
Bold = 1
|
||||
Italics = 2
|
||||
Underline = 4
|
||||
|
||||
Black = 30
|
||||
Red = 31
|
||||
Green = 32
|
||||
Yellow = 33
|
||||
Blue = 34
|
||||
Magenta = 35
|
||||
Cyan = 36
|
||||
White = 37
|
||||
|
||||
# escape sequence format string
|
||||
__fescseq = '\033[3{0}m'
|
||||
__fescseq = '\033[{0}'
|
||||
# ansi reset code
|
||||
__ansi_rst = '\033[0m'
|
||||
|
||||
__ansi_black = '\033[30m'
|
||||
__ansi_red = '\033[31m'
|
||||
__ansi_green = '\033[32m'
|
||||
__ansi_yellow = '\033[33m'
|
||||
__ansi_blue = '\033[34m'
|
||||
__ansi_magenta = '\033[35m'
|
||||
__ansi_cyan= '\033[36m'
|
||||
__ansi_white = '\033[37m'
|
||||
|
||||
@staticmethod
|
||||
def _ansi_ret(ansi):
|
||||
return ansi, Color.__ansi_white
|
||||
|
||||
@staticmethod
|
||||
def code(color: 'Color'):
|
||||
return Color.__fescseq.format(color.value)
|
||||
return Color.__fescseq.format(f'{color.value}m')
|
||||
|
||||
# move the cursor up n lines
|
||||
@staticmethod
|
||||
def mvup_code(n: int):
|
||||
return Color.__fescseq.format(f'{n}A')
|
||||
|
||||
def ansi(self):
|
||||
code = Color.code(self)
|
||||
|
|
@ -40,9 +42,18 @@ class Color(Enum):
|
|||
|
||||
# !! ULTRA PRINT !!
|
||||
def uprint(text: str,
|
||||
color: Color = Color.White,
|
||||
color: Optional[Color] = None,
|
||||
style: Optional[Color] = None,
|
||||
moveup: int = 0,
|
||||
end: str = '\n',
|
||||
flush: bool = True):
|
||||
c = color.ansi()
|
||||
text = f'{c[0]}{text}{c[1]}'
|
||||
if color is not None:
|
||||
c = color.ansi()
|
||||
text = f'{c[0]}{text}{c[1]}'
|
||||
if style is not None:
|
||||
s = style.ansi()
|
||||
tail = '' if (c is not None and c[1] == '') else s[1]
|
||||
text = f'{s[0]}{text}{tail}'
|
||||
if moveup > 0:
|
||||
text = Color.mvup_code(moveup) + text
|
||||
print(text, end=end, flush=flush)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue