Skip to content

Instantly share code, notes, and snippets.

View giuscri's full-sized avatar

Giuseppe Crinò giuscri

View GitHub Profile
@giuscri
giuscri / reducibility.py
Last active August 7, 2017 15:59
Leverage computational reducibility of vertex covers and independent sets to cover/packing problems for sets.
# 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)
@giuscri
giuscri / seiferas.py
Last active July 30, 2017 21:19
It should implement the Chen-Seiferas suffix tree presented here, http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.632.4&rep=rep1&type=pdf
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={},
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
@giuscri
giuscri / string_matching.py
Last active July 23, 2017 14:17
A collection of string matching algorithms taken from chapter 32 of CSLR.
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.
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
.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
.globl main
.globl fibonacci
.data
some_error_occurred: .asciiz "*** Some error occurred.\n"
.text
main:
sub $sp, $sp, 4
sw $ra, 0($sp)
.globl main
.globl insert
.globl delete
.globl defrag
.globl find_zero
.globl print_list
.globl fail
.data
list: .space 12
.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
.data
A:
.space 16
B:
.space 16
c:
.word 0
.text
main: