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
| class undirected_graph(dict): | |
| """An undirected graph edge list | |
| In an undirected graph edges are symmetric, so vertex order doesn't matter. | |
| Store lists or dictionaries to represent attributes. | |
| >>> a = undirected_graph() | |
| >>> a[4,5] = True | |
| >>> a[5,4] | |
| True |
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 fractions import gcd | |
| def rotate(vector, k): | |
| ''' rotate the vector to the left ''' | |
| n = len(vector) | |
| for i in range(gcd(k,n)): | |
| temp = vector[i] | |
| j = i | |
| while True: | |
| p = j + k |
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
| '''Parens | |
| Enumerate nested parenthesis. | |
| Implements Algorithm P from Knuth's the Art of Computer Programming v. 4 | |
| directly with minimal optimizations for python. | |
| Usage: python parens.py number | |
| ''' | |
| import sys |
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
| ''' | |
| Prints all sets of nested parenthesis of order [number] | |
| Usage: python printKParens.py number | |
| ''' | |
| import sys | |
| def printKParens(s, index, k_remaining): | |
| if(index == len(s)): | |
| print ''.join(s) |
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
| '''ca.py | |
| Wolfram Cellular Automata by Chris Lonnen | |
| Demonstration of Processing.py features (in both the traditional and Microsoft | |
| sense) in the form of a Wolfram 1-dimensional cellular automata. | |
| Compare to Shiffman's pure Processing implementation: | |
| http://processing.org/learning/topics/wolfram.html | |
| ''' |
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
| // simple.pde | |
| void setup() { | |
| size(400, 400); | |
| stroke(255); | |
| } | |
| void draw() { | |
| background(192, 64, 0); | |
| line(150, 25, mouseX, mouseY); |
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
| # simple.py | |
| def setup(): | |
| size(400, 400) | |
| stroke(255) | |
| def draw(): | |
| background(192, 64, 0) | |
| line(150, 25, mouseX, mouseY) |
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
| function threeTuple( array, target ) { | |
| if (isNaN(target)){return null;} | |
| array.sort(); | |
| for (var i = 0; i < array.length; i++) { | |
| var j = i+1; | |
| var k = array.length - 1; // start at the end of the array | |
| while(k > j) { | |
| summation = array[i] + array[j] + array[k]; | |
| if (summation === target) {return [i,j,k];} | |
| if (summation > target) {k--;} |
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
| function findClosest(items, value){ | |
| // a modified binary search that returns the last | |
| // index checked, whether or not it had the correct value | |
| var startIndex = 0; | |
| var stopIndex = items.length - 1; | |
| var middle = Math.floor((stopIndex + startIndex)/2); | |
| while(items[middle] != value && startIndex < stopIndex){ | |
| middle = Math.floor((stopIndex + startIndex)/2); | |
| if (value < items[middle]){ |
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
| require 'formula' | |
| class Autoconf213 <Formula | |
| url 'http://ftp.gnu.org/pub/gnu/autoconf/autoconf-2.13.tar.gz' | |
| md5 '9de56d4a161a723228220b0f425dc711' | |
| homepage 'http://www.gnu.org/software/autoconf/' | |
| def keg_only? | |
| :provided_by_osx | |
| end |
OlderNewer