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
import edu.princeton.cs.algs4.*; | |
import java.util.*; | |
public class KdTree { | |
private abstract class Node implements TreeApply { | |
protected Point2D point; | |
public abstract void apply (TreeFunction function); | |
} | |
private interface TreeFunction { |
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
# -*- mode: snippet; require-final-newline: nil -*- | |
# name: homework-sty | |
# key: homework | |
# binding: direct-keybinding | |
# -- | |
\documentclass[10pt,letterpaper]{article} | |
\usepackage[T1]{fontenc} | |
\usepackage[parfill]{parskip} % line break instead of indentation | |
\usepackage[margin=1in]{geometry} | |
\usepackage{float} % use attribute [H] to force images to stay where they should be |
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
% | |
% Listings hacks to emulate the math-style Haskell from Functional Pearls, | |
% Programming in Haskell, Pearls of Functional Algorithm Design. and other books. | |
% | |
% This is probably as close an emulation of the math-style generated with lhs2tex as I can get. | |
% | |
% Modified from: | |
% https://raw.githubusercontent.com/UCSD-PL/230-web/master/templates/haskellListings.tex | |
% |
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
(* Folds *) | |
let rec fold_right f a xs = match xs with | |
| [] -> a | |
| x :: xs -> f (fold_right f a xs) x | |
let rec fold_left f a xs = match xs with | |
| [] -> a | |
| x :: xs -> fold_left f (f a x) xs | |
(* TODO: implement monoids and the foldable typeclass with modules*) |
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
{- LANGUAGE TupleSections -} | |
import Control.Monad | |
import qualified Data.Set as S | |
--type State = String | |
type Symbol = Char | |
data DFA st = DFA { states :: [st], | |
alphabet :: [Symbol], | |
delta :: st -> Symbol -> st, | |
startSt :: st |
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
#lang racket | |
(require xml) | |
(require xml/xexpr) | |
(define to-html (compose display | |
xexpr->string)) | |
(define CONFIGS '((siteName "Andromeda") | |
(latitude 1234.567) |
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
#lang racket | |
(require test-engine/racket-tests) | |
(define (rotations lst) | |
(letrec ((go (λ (n acc) | |
(if (= n 0) acc | |
(go (sub1 n) (let ((c (car acc))) | |
`(,`(,@(cdr c) ,(car c)) ,@acc))))))) | |
(reverse (go (length lst) (list lst))))) |
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
#lang racket | |
#| | |
Simplified SXML grammar | |
<Element> ::= (<Symbol> <Children>...) | |
| (<Symbol> <AttribList> <Children>...) | |
<Children> ::= <Element> | <Value> | |
<AttribList> ::= (<Attribute> ...) | (@ <Attribute> ...) |
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
module Golf where | |
import Data.List | |
skips :: [a] -> [[a]] | |
skips xs = map (map snd) $ zipWith filter filters (replicate len ids) | |
where len = length xs | |
ids = zip [1..len] xs | |
filters = map (\n (a,_) -> a `mod` n == 0) [1..len] | |
localMaxima :: [Integer] -> [Integer] |
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
# MarkdownBlock | |
# Insert & parse Markdown anywhere, even nested in html | |
# | |
# Author: Matthew Chan <[email protected]> | |
# Date: January 2015 | |
# License: GNU GPL | |
# | |
# Usage: | |
# {% markdown %} | |
# <md_text> |