This file contains hidden or 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
| #!/usr/bin/env python3 | |
| from enum import Enum, unique | |
| @unique | |
| class Suit(Enum): | |
| Club = 1 | |
| Diamond = 2 | |
| Heart = 3 | |
| Spade = 4 |
This file contains hidden or 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
| CLUB = 1 | |
| DIAMOMD = 2 | |
| HEART = 3 | |
| SPADE = 4 |
This file contains hidden or 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
| #!/usr/bin/env python3 | |
| Repeat=((5,4),((((10,(11,(1,((((15,((((18,19),17),16),0)),14),13),12)))),8),6),(3,((9,2),7)))) | |
| Tail=(((5,(6,(7,(8,(((((((16,(17,((20,23),(15,18)))),14),13),12),11),10),9))))),2),(1,(4,3))) | |
| Char=[(((('o','i'),('v','p')),(('x','g'),(('c','m'),('s','d')))),(((('l','w'),('r','e')),(('b','h'),('u','a'))),((('j','t'),('y','f')),(('n','q'),('z','k'))))), | |
| ((('r',('s',('p','i'))),(('b',((((('j','a'),('q','o')),'h'),'k'),('y','u'))),(('d','g'),('m',(('f','w'),('v',('z','x'))))))),((('c','e'),'l'),('n','t'))), | |
| ((((('y',(('t',('f','h')),('d',('w',('k','v'))))),(((('c','j'),('n',(('p','g'),'m'))),'s'),'b')),'o'),('a','e')),((('r','u'),'i'),'l')), | |
| ((('i',(('r','l'),'u')),'e'),(('h',('k','o')),('a',('t',(((((((('w','v'),('g','f')),('z','p')),'n'),(('d','m'),('b','q'))),'c'),'s'),'y'))))), | |
| ((((('n',(('t',('v','p')),('b','w'))),'l'),(('s','y'),('u',(('f',(((('q','k'),'z'),'j'),'c')),'g')))),'a'),('e',((((('h','m'),'d'),'r'),'o'),'i'))), | |
| (('r',((('c',('i',('v',('k',('z',('j','q')))))),'t'),('l','a'))),(( |
This file contains hidden or 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
| #!/usr/bin/env python3 | |
| Repeat=((5,4),((((10,(11,(1,((((15,((((18,19),17),16),0)),14),13),12)))),8),6),(3,((9,2),7)))) | |
| Tail=(((5,(6,(7,(8,(((((((16,(17,((20,23),(15,18)))),14),13),12),11),10),9))))),2),(1,(4,3))) | |
| Char=(((('d',(('k',('w','v')),'g')),'i'),((('m',('b','p')),'r'),('l','o'))),(('e',('t',('u','c'))),((((('f',('z',(('j','q'),'x'))),'h'),'y'),'s'),('n','a')))) | |
| NumWords=67527 | |
| Bits=r''' | |
| jjvjG9QF+ojhTtgjSXb83952mERR72W27AD9nBWMxnfU5y/PfpghOLNuB+9gfkTqx5WjezfRfs7CAyJ1 | |
| NiMAyJ1KfK+ahkTqeeGWuwx7K+jp3K7Yc+3VL1vl1H2vv7W3UXdbOXrGWCz9SEHOX7nss7XxPZnQl3h7 | |
| YRTUxG/pNK9Van8v3rq6nXNt2dE4x728+951TTsjbunI+zLbYbpuyYXNN/be15XqKry/ei5V1756MdeB | |
| ... |
This file contains hidden or 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 huffman import HuffmanEncoder | |
| from binary_tools import BitBuffer | |
| class Compressor: | |
| def Name(self): | |
| return 'prefix' | |
| def Compress(self, words): | |
| repeatRoot, tailRoot, charRoot = self._HuffmanCodes(words) | |
| repeatCode = repeatRoot.MakeEncoding() |
This file contains hidden or 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
| #!/usr/bin/env python3 | |
| Char=((('e',('l',('p','m'))),('\n',('s','t'))),((('o','n'),('r',('d','u'))),(((('b',((('j','q'),('z','x')),'v')),('y','g')),'i'),('a',('c',('h',('f',('w','k')))))))) | |
| NumChars=636945 | |
| Bits=r''' | |
| 5d1Wx9X+u6rf0F+XYLsOXYd7l2He1nXYd7/XYd59niXYd67LsOtaJXYd+ddhxaJ5wuw4tE8+xK7DiiQu | |
| w45hQXYdNoldh02iRZdh02iTiXXYdT765c+xK7DmC7DmFl2HMDiXXYc3y7Dm+Fl2HN8cS67Dm3l2HNvl | |
| 2HOF2HODiXXYc+zmuw59Zdhz4iL0uw531l2HO8bS7DsXvEuww5dhh3sl2GHPvEuww599xLsMOfWXYYBd | |
| ... | |
| dYq/vfbOrFXK6xV633yxX8NFENzFLFf2jDvf6xX9re+ErFZZyD8sVlnIPz94cFiss5B+fiDLFZZx7vPd | |
| liss4t3nyJYrLOD8sVlnB4o32+WKyzg+Xg4ZYrLOD5eh+WKyzg32RF3hwWKyzg32RFc6xWWcGcVyxWWc |
This file contains hidden or 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 huffman import HuffmanEncoder | |
| from binary_tools import BitBuffer | |
| class Compressor: | |
| def Name(self): | |
| return 'letters' | |
| def Compress(self, words): | |
| charRoot = self._HuffmanCode(words) | |
| charCode = charRoot.MakeEncoding() |
This file contains hidden or 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 HuffmanEncoder: | |
| def __init__(self): | |
| self.table = {} | |
| def Tally(self, symbol): | |
| self.table[symbol] = 1 + self.table.get(symbol, 0) | |
| def Compile(self): | |
| if len(self.table) == 0: | |
| raise Exception('Huffman encoder needs to have at least one symbol.') |
This file contains hidden or 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 HuffmanNode: | |
| def __init__(self, symbol, count, left, right): | |
| self.symbol = symbol | |
| self.count = count | |
| self.left = left | |
| self.right = right | |
| def __lt__(self, other): | |
| # Allows nodes to be sorted by count | |
| return self.count < other.count |
This file contains hidden or 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 BitBuffer: | |
| def __init__(self): | |
| self.buf = bytearray() | |
| self.accum = 0 | |
| self.nbits = 0 | |
| self.column = 0 | |
| def Append(self, pattern): | |
| data, dbits = pattern | |
| while self.nbits + dbits >= 6: |