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
# book partitioning so each person reads roughly the same amount | |
import math | |
def solve(pages, people): | |
n = len(pages) | |
m = [[0 for j in range(people)] for i in range(n)] | |
s = [[-1 for j in range(people)] for i in range(n)] | |
# work left to right |
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
all: vmem | |
vmem: vmem.c | |
clang vmem.c -o vmem | |
test: vmem input1.txt | |
./vmem input1.txt LRU | |
./vmem input1.txt CLOCK | |
test2: vmem input2.txt |
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
# assembly line scheduling problem, modified with consecutive station bonus | |
import math | |
C_FACTOR = 1 | |
def solve(e1, e2, a1, a2, t1, t2, x1, x2): | |
""" finds fastest route thru factory """ | |
assert len(a1) == len(a2) | |
n = len(a1) |
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
# optimized parenthesization of matrix multiplication | |
import math | |
def print_2d(arr): | |
for row in arr: | |
for col in row: | |
if col == math.inf: | |
print(col, end=" ") |
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
# longest common subsequence | |
def lcs(x, y): | |
""" returns longest common sequence length, exponential runtime complexity """ | |
if len(x) == 0 or len(y) == 0: | |
return 0 | |
elif x[-1] == y[-1]: | |
return lcs(x[:-1], y[:-1]) + 1 | |
else: | |
return max(lcs(x[:-1], y), |
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
all: buffer | |
buffer: buffer.h buffer.c | |
clang buffer.c -o buffer -lpthread | |
test: buffer | |
./buffer 1 1 5 | |
test2: buffer | |
./buffer 20 20 20 |
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
all: simulator | |
simulator: simulator.o queue.o | |
clang simulator.o queue.o -o simulator | |
simulator.o: simulator.c simulator.h | |
clang -g -c simulator.c -Wall | |
queue.o: queue.c simulator.h | |
clang -g -c queue.c -Wall |
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
import unittest | |
def median(a, b): | |
""" finds the low median of 2 sorted arrays, a and b """ | |
def _median(a, b, index): | |
if index == 0: | |
if len(a) == 0: | |
return b[0] |
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
all: observer | |
observer: observer.c | |
clang observer.c -o observer | |
clean: | |
rm -f observer | |
test: observer | |
./observer |
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
# Sudoku puzzle solver | |
def make_sudoku_board(): | |
return [ | |
[5, 3, 0, 0, 7, 0, 0, 0, 0], | |
[6, 0, 0, 1, 9, 5, 0, 0, 0], | |
[0, 9, 8, 0, 0, 0, 0, 6, 0], | |
[8, 0, 0, 0, 6, 0, 0, 0, 3], | |
[4, 0, 0, 8, 0, 3, 0, 0, 1], |
NewerOlder