This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.
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 |
| 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 |
| # 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 |
| # 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 |