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__/
|
||||||
64
m.py
64
m.py
|
|
@ -2,24 +2,68 @@
|
||||||
from prbraid.math import *
|
from prbraid.math import *
|
||||||
from prbraid.color import *
|
from prbraid.color import *
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
PROMPT = '[n]: '
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
while True:
|
while True:
|
||||||
x = None
|
n = None
|
||||||
|
strlen_n = None
|
||||||
try:
|
try:
|
||||||
uprint('This is red!', color=Color.Red, end=' ', flush=False)
|
uprint(PROMPT, color=Color.Blue, end='')
|
||||||
uprint('And this is green!', color=Color.Green, flush=True)
|
n = input()
|
||||||
x = int(input('[n]: '))
|
strlen_n = len(n)
|
||||||
|
n = int(n)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
continue
|
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
|
# 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)
|
# find all invertible elements (skipped for now)
|
||||||
for i in range(x):
|
for a in range(n):
|
||||||
lpad = ' ' * (lpadded - len(str(i)))
|
orb = orbit(a, n)
|
||||||
grp = orbit(i, x)
|
ord = len(orb)
|
||||||
print(f'{lpad}{i} -> {len(grp)} | {grp}')
|
|
||||||
|
# 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
|
print() # empty new line
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
@ -27,5 +71,3 @@ if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
except (KeyboardInterrupt, EOFError):
|
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 enum import Enum
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
class Color(Enum):
|
class Color(Enum):
|
||||||
Black = 0
|
Reset = 0
|
||||||
Red = 1
|
Bold = 1
|
||||||
Green = 2
|
Italics = 2
|
||||||
Yellow = 3
|
Underline = 4
|
||||||
Blue = 4
|
|
||||||
Magenta = 5
|
Black = 30
|
||||||
Cyan = 6
|
Red = 31
|
||||||
White = 7
|
Green = 32
|
||||||
|
Yellow = 33
|
||||||
|
Blue = 34
|
||||||
|
Magenta = 35
|
||||||
|
Cyan = 36
|
||||||
|
White = 37
|
||||||
|
|
||||||
# escape sequence format string
|
# escape sequence format string
|
||||||
__fescseq = '\033[3{0}m'
|
__fescseq = '\033[{0}'
|
||||||
# ansi reset code
|
# ansi reset code
|
||||||
__ansi_rst = '\033[0m'
|
__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
|
@staticmethod
|
||||||
def _ansi_ret(ansi):
|
def _ansi_ret(ansi):
|
||||||
return ansi, Color.__ansi_white
|
return ansi, Color.__ansi_white
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def code(color: 'Color'):
|
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):
|
def ansi(self):
|
||||||
code = Color.code(self)
|
code = Color.code(self)
|
||||||
|
|
@ -40,9 +42,18 @@ class Color(Enum):
|
||||||
|
|
||||||
# !! ULTRA PRINT !!
|
# !! ULTRA PRINT !!
|
||||||
def uprint(text: str,
|
def uprint(text: str,
|
||||||
color: Color = Color.White,
|
color: Optional[Color] = None,
|
||||||
|
style: Optional[Color] = None,
|
||||||
|
moveup: int = 0,
|
||||||
end: str = '\n',
|
end: str = '\n',
|
||||||
flush: bool = True):
|
flush: bool = True):
|
||||||
|
if color is not None:
|
||||||
c = color.ansi()
|
c = color.ansi()
|
||||||
text = f'{c[0]}{text}{c[1]}'
|
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)
|
print(text, end=end, flush=flush)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue