lalalala
This commit is contained in:
commit
c743ca0b85
3 changed files with 103 additions and 0 deletions
31
m.py
Normal file
31
m.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# Modulo Test
|
||||
from prbraid.math import *
|
||||
from prbraid.color import *
|
||||
|
||||
def main():
|
||||
while True:
|
||||
x = 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]: '))
|
||||
except ValueError:
|
||||
continue
|
||||
|
||||
# calculate left padding to align i values
|
||||
lpadded = len(str(x))
|
||||
|
||||
# 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}')
|
||||
print() # empty new line
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
main()
|
||||
except (KeyboardInterrupt, EOFError):
|
||||
pass
|
||||
|
||||
|
||||
48
prbraid/color.py
Normal file
48
prbraid/color.py
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
from enum import Enum
|
||||
|
||||
class Color(Enum):
|
||||
Black = 0
|
||||
Red = 1
|
||||
Green = 2
|
||||
Yellow = 3
|
||||
Blue = 4
|
||||
Magenta = 5
|
||||
Cyan = 6
|
||||
White = 7
|
||||
|
||||
# escape sequence format string
|
||||
__fescseq = '\033[3{0}m'
|
||||
# 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)
|
||||
|
||||
def ansi(self):
|
||||
code = Color.code(self)
|
||||
if self == Color.White:
|
||||
return code, ''
|
||||
return code, Color.__ansi_rst
|
||||
|
||||
# !! ULTRA PRINT !!
|
||||
def uprint(text: str,
|
||||
color: Color = Color.White,
|
||||
end: str = '\n',
|
||||
flush: bool = True):
|
||||
c = color.ansi()
|
||||
text = f'{c[0]}{text}{c[1]}'
|
||||
print(text, end=end, flush=flush)
|
||||
24
prbraid/math.py
Normal file
24
prbraid/math.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
# Euler's Totient (Phi) Function
|
||||
def totient(n):
|
||||
phi = int(n > 1 and n)
|
||||
for p in range(2, int(n ** .5) + 1):
|
||||
if not n % p:
|
||||
phi -= phi // p
|
||||
while not n % p:
|
||||
n //= p
|
||||
#if n is > 1 it means it is prime
|
||||
if n > 1: phi -= phi // n
|
||||
return phi
|
||||
|
||||
|
||||
def orbit(b, m):
|
||||
generated = []
|
||||
x = b
|
||||
for i in range(m):
|
||||
x = (x * b) % m
|
||||
if x not in generated:
|
||||
generated.append(x)
|
||||
return generated
|
||||
|
||||
def order(b, m):
|
||||
return len(orbit(b, m))
|
||||
Loading…
Add table
Add a link
Reference in a new issue