This commit is contained in:
Emile Clark-Boman 2025-06-11 11:11:35 +10:00
commit c743ca0b85
3 changed files with 103 additions and 0 deletions

48
prbraid/color.py Normal file
View 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
View 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))