from irr import Irr from dyn import Dyn import math #factorial, with memoization fact = Dyn() fact.addBaseCase(0, 1) def factRecFn(n, fact): return n * fact(n - 1) fact.recFn = factRecFn #compute the number of permutations in S_n with cycle structure l def countType(l,n): ls = {} x = fact(n) for a in l: if a in ls: ls[a] += 1 else: ls[a] = 1 x /= a for a in ls: x /= fact(ls[a]) return x #compute the number of partitions with all odd parts of given size with all parts under a given size, with memoization partOdd = Dyn() partOdd.addBaseCase((0,0), [[]])
part = Dyn() part.addBaseCase((0,0), [[]]) def parts(tup, part): if tup[0] < tup[1]: return part((tup[0], tup[0])) l = [] k = 1 while k <= tup[0] and k <= tup[1]: p = part((tup[0]-k, k)) l += [[k] + a for a in p] k += 1 return l part.recFn = parts #size of the triangle n = int(sys.argv[1]) #is a rep on S_nn... that is, nn is the nth triangular number nn = n * (n + 1) >> 1 #build the partition and get it into a tuple format l = range(1,n+1) l.reverse() l = tuple(l) rep = Irr(l, nn) ch = Char(rep)