Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Project: Peter's Files
Views: 3893
Visibility: Unlisted (only visible to those who know the link)
Image: ubuntu1804
Kernel: Python 3 (system-wide)

General Pascal's Triangle

def make_triangle(op:"function", rep:"function", gen_row:list, num_rows:int, aux:int, sp:int=1): last_row = gen_row ch = len(rep(gen_row[0], aux)) t = 0 if (ch % 2) != (sp % 2) and sp != -1: sp += 1 if sp < 0: t = sp * -1 ol = (abs(ch - sp) // 2) + (ch if sp >= ch else sp) for i in range(num_rows + 1): print((" " * ol * (num_rows - i) if sp >= 0 else "") + (" " * sp if sp >= 0 else "\t"*t).join(rep(element,aux) for element in last_row)) last_row = [gen_row[0]] + [op(last_row[i], last_row[i+1], aux) for i in range(len(last_row) - 1)] + [gen_row[-1]]

Zn\mathbb{Z}_n

# these define the semigroup structure and how the elements are displayed def op_Z_n(a,b,aux): return (a + b) % aux def rep_Z_n(a,aux=1): return str(a)
# Z_4 make_triangle(op_Z_n, rep_Z_n, gen_row=[1], num_rows=10, aux=4, sp=3)
1 1 1 1 2 1 1 3 3 1 1 0 2 0 1 1 1 2 2 1 1 1 2 3 0 3 2 1 1 3 1 3 3 1 3 1 1 0 0 0 2 0 0 0 1 1 1 0 0 2 2 0 0 1 1 1 2 1 0 2 0 2 0 1 2 1
# Z_7 make_triangle(op_Z_n, rep_Z_n, gen_row=[1], num_rows=15, aux=7, sp=3)
1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 3 3 5 1 1 6 1 6 1 6 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 2 1 0 0 0 0 1 2 1 1 3 3 1 0 0 0 1 3 3 1 1 4 6 4 1 0 0 1 4 6 4 1 1 5 3 3 5 1 0 1 5 3 3 5 1 1 6 1 6 1 6 1 1 6 1 6 1 6 1 1 0 0 0 0 0 0 2 0 0 0 0 0 0 1 1 1 0 0 0 0 0 2 2 0 0 0 0 0 1 1

DnD_n

def op_D_n(a,b,aux): # r^ks^e --> (k,e) return ((a[0] + b[0] * (1 - 2 * a[1])) % aux, (a[1] + b[1]) % 2) def rep_D_n(a,aux=1): if a == (0,0): return " e " return (f"r^{a[0]}" if a[0] > 1 else {0:" ", 1:" r"}[a[0]]) + {0:" ", 1:"s "}[a[1]]
# D_3 make_triangle(op_D_n, rep_D_n, [(1,1),(2,0)], num_rows=12, aux = 3, sp=2)
rs r^2 rs r^2s r^2 rs r^2 s r^2 rs r^2s r^2s rs r^2 rs r^2 e r r^2s r^2 rs r^2s r^2 r s s r^2 rs r^2 s e rs e rs r^2 rs r^2s r^2s s rs rs rs r^2s r^2 rs r^2 e r^2 r^2 e e r^2 s r^2 rs r^2s r^2 r^2 r r^2 e r^2 r^2s rs r^2 rs r^2 s r e e r^2 r^2 rs r r^2s r^2 rs r^2s r^2s r^2s r e r^2 r s s s s r^2 rs r^2 e e rs r r^2 e rs e e e rs r^2

SnS_n

a,b=eval(input()) p=a+b o=[] for i in range(1,1+max(map(max,p))): if not any(i in t for t in o): u=(i,) m=i while True: for t in p[::-1]: if m in t: m=t[(t.index(m)+1)%len(t)] if m == i: o+=[u] break u+=(m,) print(o)
a,b=eval(input()) p=a+b o=[] for i in range(1,1+max(map(max,p))): if not any(i in t for t in o): u=(i,) m=i while True: for t in p[::-1]: if m in t: m=t[(t.index(m)+1)%len(t)] if m == i: o+=[u] break u+=(m,) print(o)
def op_S_n(a,b,aux): a.reverse() b.reverse() out = [] for i in range(1,aux+1): if any(i in tup for tup in out): continue build = [i] maps_to = i while True: for tup in b + a: if maps_to in tup: maps_to = tup[(tup.index(maps_to) + 1) % len(tup)] if maps_to == i: out += [tuple(build)] break build += [maps_to] return out from math import floor, ceil def rep_S_n(a,aux): s = "".join("(" + " ".join(str(el) for el in tup) + ")" for tup in a if len(tup) != 1) s = s if s != "" else "(1)" pad = (aux // 2 + 1) * 5 - len(s) return " " * ceil(pad / 2) + s + " " * floor(pad/2)
# S_5 make_triangle(op_S_n, rep_S_n, [[(1,2,3,4)]], num_rows=7, aux = 5, sp=0)
(1 2 3 4) (1 2 3 4) (1 2 3 4) (1 2 3 4) (1 3)(2 4) (1 2 3 4) (1 2 3 4) (1 4 3 2) (1 4 3 2) (1 2 3 4) (1 2 3 4) (1) (1 3)(2 4) (1) (1 2 3 4) (1 2 3 4) (1 2 3 4) (1 3)(2 4) (1 3)(2 4) (1 2 3 4) (1 2 3 4) (1 2 3 4) (1 3)(2 4) (1 4 3 2) (1) (1 4 3 2) (1 3)(2 4) (1 2 3 4) (1 2 3 4) (1 4 3 2) (1 2 3 4) (1 4 3 2) (1 4 3 2) (1 2 3 4) (1 4 3 2) (1 2 3 4)