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
# https://homes.di.unimi.it/cesa-bianchi/Algo2/Note/np.pdf | |
from itertools import chain | |
from itertools import combinations | |
from pdb import set_trace as brk | |
def powerset(iterable): | |
"""Computes the powerset of an iterable.""" | |
if iterable is None: return None | |
s = tuple(iterable) |
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 copy import copy | |
from itertools import takewhile | |
from pdb import set_trace as brk | |
def is_prefix(b, a): | |
"""Tests if b is a prefix of a.""" | |
return a[:len(b)] == b | |
class Node: | |
def __init__(self, pathstring, parent=None, children={}, |
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
XTerm.termName: xterm-256color | |
XTerm.vt100.color0: rgb:07/36/42 | |
XTerm.vt100.color1: rgb:dc/32/2f | |
XTerm.vt100.color2: rgb:85/99/00 | |
XTerm.vt100.color3: rgb:b5/89/00 | |
XTerm.vt100.color4: rgb:26/8b/d2 | |
XTerm.vt100.color5: rgb:d3/36/82 | |
XTerm.vt100.color6: rgb:2a/a1/98 | |
XTerm.vt100.color7: rgb:ee/e8/d5 | |
XTerm.vt100.color8: rgb:00/2b/36 |
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 functools import reduce | |
from string import ascii_lowercase | |
def naive_string_matching(T, P): | |
"""Computes all the occurrences of P in T. | |
Cost of this procedure is O(n-m+1 * m) | |
where n, m are the length of T and of P | |
respectively. |
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
def zero_left_pad(s, l=32): | |
""" | |
Pad a string with '0' such that | |
the resulting length equals to | |
a fixed amount. | |
Args: | |
s (str): string to pad | |
l (int): length of the resulting string |
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
.data | |
hi: .asciiz "aabbaa" | |
.text | |
main: | |
sub $sp, $sp, 4 | |
sw $ra, 0($sp) | |
sub $sp, $sp, 4 | |
sw $fp, 0($sp) | |
move $fp, $sp |
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
.globl main | |
.globl fibonacci | |
.data | |
some_error_occurred: .asciiz "*** Some error occurred.\n" | |
.text | |
main: | |
sub $sp, $sp, 4 | |
sw $ra, 0($sp) |
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
.globl main | |
.globl insert | |
.globl delete | |
.globl defrag | |
.globl find_zero | |
.globl print_list | |
.globl fail | |
.data | |
list: .space 12 |
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
.data | |
type_a_number: .asciiz "*** Type a number (falling back to 0): " | |
type_another_number: .asciiz "*** Type another number (falling back to 0): " | |
numbers_you_typed_are: .asciiz "*** Numbers you typed are: " | |
.text | |
main: | |
li $a0, 8 | |
li $v0, 9 | |
syscall |
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
.data | |
A: | |
.space 16 | |
B: | |
.space 16 | |
c: | |
.word 0 | |
.text | |
main: |