Skip to content

Instantly share code, notes, and snippets.

@matt-y
matt-y / gist:3398846
Created August 20, 2012 00:29
picking a side on a rectangle bounded by window_height, and window_width
def new_edge_point(self):
side = random.randint(1,4)
if side == 1:
#left side
return Vector(0, random.randint(0, constants.window_height))
elif side == 2:
#right side
return Vector(constants.window_width, random.randint(0, constants.window_height))
elif side == 3:
#top
@matt-y
matt-y / tongues_test.py
Created April 17, 2012 01:29
tongues solution (incorrect)
import sys
mapping = {
'a':'y',
'b':'h',
'c':'e',
'd':'s',
'e':'o',
'f':'c',
'g':'v',
@matt-y
matt-y / gist:1921802
Created February 27, 2012 06:01
ngram
class SpellCheck(object):
def __init__(self):
self.trigram_store = {}
def compute_ngrams(self,word, n=3):
'''
Given a word of length N, this fucntion will compute N-(n-1) n-grams
A trigram(n=3) is three letters ex: given 'that', we have 4-2=2 trigrams:
'tha' and 'hat'
@matt-y
matt-y / 8queens.java
Created February 15, 2012 00:49
8 queens solution
import java.util.LinkedList;
/**
* User: mattosaurus
* Date: 1/30/12
* Time: 8:10 PM
*/
public class Queens {
private int n;
private LinkedList<Integer> state;
@matt-y
matt-y / gist:1708917
Created January 31, 2012 04:56
generating one solution to "n" queens
import java.util.LinkedList;
/**
* User: mattosaurus
* Date: 1/30/12
* Time: 8:10 PM
*/
public class Queens {
private int n;
private LinkedList<Integer> state;
@matt-y
matt-y / gist:1695260
Created January 28, 2012 17:55
Trying to write an "abstract" product procedure
;;this recursive one works
(define (prod term a next b)
(if (> a b)
1
(* (term a)
(prod term (next a) next b))))
;;this iterative one does not
;;Ex1.31
;;iterative product procedure
@matt-y
matt-y / gist:1674974
Created January 25, 2012 05:50
list check
(define (list?? maybe-list)
(cond ((null? maybe-list) #t)
((and (pair? maybe-list)
(list?? (cdr maybe-list))) #t)
(else #f)))
;;recursive
(define (list-len list)
(if (null? list)
0
@matt-y
matt-y / gist:1335826
Created November 3, 2011 05:16
template
public class Problem {
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(new File("voting.in"));
String s = in.nextLine();
while (!s.equals("#")) {
//etc
}
}
}