This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Monoid Homology Calculator | |
written by Dennis Sweeney | |
Given a monoid M, we can produce a topological space (cw complex) BM, | |
whose n-cells are n-tuples of non-identity elements of M. | |
This program computes the integral homology of the space BM. | |
The problem of deciding whether two words are equal is not computable, | |
so we restrict to nice classes of monoid presentations. In particular, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Matrix: | |
def __init__(self, arr, n=None): | |
if isinstance(arr, Matrix): | |
self.arr = [list(row) for row in arr.arr] | |
self.m = arr.m | |
self.n = arr.n | |
else: | |
self.arr = [list(row) for row in arr] | |
self.m = len(arr) | |
if not arr: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from turtle import * | |
def turns(): | |
s = [] | |
while True: | |
yield 90 | |
fold = [-x for x in reversed(s)] | |
yield from fold | |
s += [90] + fold | |
hideturtle() | |
speed(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Find the number of nonnegative integer solutions (x_1, ..., x_n) | |
to the equation a_1*x_1 + ...+ a_k*x_k = n, | |
where each a_i and n are positive integers. | |
Example: to find the number of ways to make $10.00 out of | |
1-, 5-, 10-, and 25-cent coins: | |
>>> change(1000, (1, 5, 10, 25)) | |
142511 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LazyProductObject: | |
# Assume there are n >= 1 iterators, with repeat = r. | |
# len(pools) == n and len(indices) == len(result) == n*r | |
# pools[0:num_incomplete_pools] are lists of items that will still | |
# get added to from iterators, while pools[num_incomplete_pools:n] | |
# are finished and don not need to be re-modified. | |
# If repeat >= 2: | |
# then the pools will fill up as we iterate the first time | |
# over all possible result[(n-1)*r:n*r] | |
# If repeat == 1: |
This file has been truncated, but you can view the full file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
needles = ['H', 'F', 'C', 'E', 'D', 'G', 'A', 'B', 'L', 'U', 'AA', 'BA', 'AB', 'IB', 'EA', 'AD', 'AQ', 'BS', 'SA', 'AK', 'HA', 'GI', 'AP', 'FP', 'IN', 'FG', 'DQN', 'ABJ', 'GKC', 'AAD', 'IDM', 'BAB', 'JAB', 'CBD', 'AEC', 'CDB', 'AXA', 'BTG', 'RBC', 'VAC', 'YCB', 'AAZ', 'KAG', 'BHA', 'BFC', 'BAD', 'DCHU', 'BCIC', 'AASX', 'AAUU', 'AEDF', 'AAAA', 'HAQB', 'CBCA', 'AAUA', 'IBDA', 'BAKJ', 'AACC', 'BBEC', 'AABG', 'CAJC', 'EOCA', 'BAPL', 'ACAP', 'ADFL', 'HBCL', 'LABVF', 'EHRIR', 'AADSH', 'CCIBL', 'MEAKB', 'RIABB', 'BFHBA', 'GDAAN', 'AALCH', 'TABAH', 'RDAAH', 'BNAZA', 'BBCMB', 'AALGN', 'AAPWK', 'BYABD', 'MGBCK', 'XFFCH', 'ABAAX', 'BACDB', 'AVAAHA', 'DMPAXA', 'ACOSQF', 'ADNCBN', 'BLCDXA', 'AAHPGA', 'AFCBAD', 'CFTUBF', 'BDQAEB', 'AAABCC', 'LTHEEG', 'YJTCIA', 'BDAFBI', 'BBFBAG', 'FAAEBA', 'DBRBKI', 'EFHFIH', 'BHACAO', 'AAGDVD', 'PBDLOA', 'LPACABC', 'ATAJEEN', 'GBMXAAM', 'AALMCBY', 'AMABEQA', 'FFDAOCR', 'AABCDTC', 'LAAPAFA', 'EBHADDA', 'FWABCAM', 'DBJOIAF', 'IADNCAB', 'ABCDBAT', 'EAAAAIC', 'BCARAAT', 'TIGOEAC', 'ABACJKG', |