Skip to content

Instantly share code, notes, and snippets.

@qzdc00
qzdc00 / KdTree.java
Created January 7, 2015 20:26
homework for algs4 week 5
public class KdTree {
private Node root;
private static final boolean X = true;
private static final boolean Y = false;
private class Node {
private Point2D p;
@qzdc00
qzdc00 / finalhw.py
Created November 25, 2014 19:07
homework for PythonMOOC one year ago...... http://www.codeskulptor.org/#user38_U8p9m2tTUF_2.py
# implementation of Spaceship - program template for RiceRocks
import simplegui
import math
import random
# globals for user interface
WIDTH = 800
HEIGHT = 600
score = 0
lives = 3
@qzdc00
qzdc00 / hw7.rb
Last active August 29, 2015 14:10
hw7/WashingtonPLMOOC
# University of Washington, Programming Languages, Homework 7, hw7.rb
# (See also ML code)
# a little language for 2D geometry objects
# each subclass of GeometryExpression, including subclasses of GeometryValue,
# needs to respond to messages preprocess_prog and eval_prog
#
# each subclass of GeometryValue additionally needs:
# * shift
@qzdc00
qzdc00 / hw6assignment.rb
Last active August 29, 2015 14:10
hw6/WashingtonPLMOOC
# University of Washington, Programming Languages, Homework 6, hw6runner.rb
# This is the only file you turn in, so do not modify the other files as
# part of your solution.
class MyPiece < Piece
# The constant All_My_Pieces should be declared here
All_My_Pieces = [[[[0, 0], [1, 0], [0, 1], [1, 1]]], # square (only needs one)
rotations([[0, 0], [-1, 0], [1, 0], [0, -1]]), # T
[[[0, 0], [-1, 0], [1, 0], [2, 0]], # long (only needs two)
@qzdc00
qzdc00 / hw5.rkt
Created November 25, 2014 18:41
hw5/WashingtonPLMOOC
;; Programming Languages, Homework 5
#lang racket
(provide (all-defined-out)) ;; so we can put tests in a second file
;; definition of structures for MUPL programs - Do NOT change
(struct var (string) #:transparent) ;; a variable, e.g., (var "foo")
(struct int (num) #:transparent) ;; a constant number, e.g., (int 17)
(struct add (e1 e2) #:transparent) ;; add two expressions
(struct ifgreater (e1 e2 e3 e4) #:transparent) ;; if e1 > e2 then e3 else e4
@qzdc00
qzdc00 / hw4.rkt
Created November 25, 2014 18:40
hw4/WashingtonPLMOOC
#lang racket
(provide (all-defined-out)) ;; so we can put tests in a second file
;; put your code below
(define sequence
(lambda (low high stride)
(if (> low high)
@qzdc00
qzdc00 / hw3provided.sml
Created November 25, 2014 18:36
hw3/WashingtonPLMOOC
(* Coursera Programming Languages, Homework 3, Provided Code *)
exception NoAnswer
datatype pattern = Wildcard
| Variable of string
| UnitP
| ConstP of int
| TupleP of pattern list
| ConstructorP of string * pattern
@qzdc00
qzdc00 / hw2provided.sml
Last active August 29, 2015 14:10
hw2/WashingtonPLMOOC
(* Dan Grossman, Coursera PL, HW2 Provided Code *)
(* if you use this function to compare two strings (returns true if the same
string), then you avoid several of the functions in problem 1 having
polymorphic types that may be confusing *)
fun same_string(s1 : string, s2 : string) =
s1 = s2
(* put your solutions for problem 1 here *)
@qzdc00
qzdc00 / hw1.sml
Last active August 29, 2015 14:10
hw1/WashingtonPLMOOC
fun is_older(date1 : int*int*int, date2: int*int*int) =
if #1 date1 <> #1 date2
then
if #1 date1 < #1 date2
then true
else false
else
if #2 date1 <> #2 date2
then
if #2 date1 < #2 date2