Skip to content

Instantly share code, notes, and snippets.

View dtroupe18's full-sized avatar

Dave T dtroupe18

  • Los Angeles
View GitHub Profile
@dtroupe18
dtroupe18 / GIF-Screencast-OSX.md
Created June 16, 2017 16:54 — forked from dergachev/GIF-Screencast-OSX.md
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

# A 3x3 magic square is a 3x3 grid of the numbers 1-9 such that each row
# column and major diagonal adds up to 15
# Write a function that, given a grid containing the numbers 1-9,
# determines whether it's a magic square.
# Use whatever format you want for the grid, such as a 2-dimensional array,
# or a 1-dimensional array of length 9, or a function that takes 9 arguments.
# You do not need to parse the grid from the program's input,
# but you can if you want to. You don't need to check that each of the 9 numbers
# appears in the grid: assume this to be true
@dtroupe18
dtroupe18 / CandM.py
Created May 17, 2016 16:08
Cannibals and Missionaries
class State(): # class that represents the current state of the problem as we work on it
def __init__(self, cannibalLeft, missionaryLeft, boat, cannibalRight, missionaryRight):
self.cannibalLeft = cannibalLeft
self.cannibalRight = cannibalRight
self.missionaryLeft = missionaryLeft
self.missionaryRight = missionaryRight
self.boat = boat
@dtroupe18
dtroupe18 / DP_MatrixMultiplication.py
Created May 17, 2016 16:07
Dynamic Programming Matrix Multiplication
# p = an array of numbers, where p[i] represents the side length of a matrix
# example p = [5, 2, 3] 5 x 2 and 2 x 3 matrix in that order
def MatrixChainMult(p):
n = len(p) - 1 # number of matrices in our multiplication problem
cost = [[0 for i in range(n)] for j in range(n)]
# creates and n x n matrix, we could use (n-1)x(n-1) matrix
@dtroupe18
dtroupe18 / KnapSackDP.py
Created May 17, 2016 16:06
0-1 KnapSack Problem
# items is a set of tuples (itemName, weight, value)
# limit is the max amount of weight the knapsack can hold
# this algorithm assumes each item can only be taken once!
def KnapSack(items, limit):
# initialize a table with all zero values item rows and weight columns!
table = [[0 for w in range(limit + 1)] for j in range(len(items) + 1)]
# iterate over each row