This file contains 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 MicroBlogger | |
def self.start | |
loop do | |
printf "enter command: " | |
Cmd.execute(gets.chomp) | |
end | |
end | |
module Cmd | |
def self.commands |
This file contains 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
type Edge = (Point, Point) | |
type Point = (Int, Int) | |
type Poly = [ Point ] | |
type Vector = (Int, Int) | |
crossProduct :: Vector -> Vector -> Int | |
crossProduct (x1,y1) (x2,y2) = (x1*y2) - (y1*x2) | |
-- Transform a list of points into a list of edges | |
polyEdges :: Poly -> [ Edge ] |
This file contains 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 Simon Thompson's excellent "The Craft of Functional Programming" | |
-- | |
-- Find the "edit distance" between two strings using five basic | |
-- editing operations: | |
-- | |
-- 1) Change one character into another | |
-- 2) Copy a character | |
-- 3) Delete a character | |
-- 4) Insert a character | |
-- 5) Delete (kill) to the end of the string |
This file contains 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
;; Step 1 | |
(define (valid? a) | |
(< a 10)) | |
(define/contract (foo a b) | |
(->i ([x valid?] [y any/c]) any) | |
(+ a b)) | |
;; Step 2 | |
(define (valid? max a) |
This file contains 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
(* Solve the Cracker Barrel Peg Board Puzzle in OCaml *) | |
open Core.Std | |
open Core.Core_list | |
let isOccupied b p = mem b p | |
let isEmpty b p = not (isOccupied b p) | |
let isPos (r,c) = r >= 0 && r < 5 && c >= 0 && c <= r | |
(* Possible moves for one position *) | |
let positionMoves b p = let (r,c) = p in |
This file contains 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 ItemAging | |
AGING_FUNCTIONS = { | |
'NORMAL ITEM' => ->(s,q) { normal(s,q) }, | |
'Aged Brie' => ->(s,q) { brie(s,q) }, | |
'Backstage passes to a TAFKAL80ETC concert' => ->(s,q) { backstage(s,q) }, | |
'Conjured Mana Cake' => ->(s,q) { conjured(s,q) }, | |
} | |
# A convenience function. The *only* function in the module that | |
# mutates non-local state. |
This file contains 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
The Westminster Shorter Catechism | |
================================= | |
The original text of 1647, with the Assembly's proof texts. | |
1. What is the chief end of man? | |
Man's chief end is to glorify God,(1) and to enjoy him for ever.(2) | |
(1) I Cor. 10:31; Rom. 11:36. [ Ps 86; Is 60:21; Rev 4:11 ] |
This file contains 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 | |
; Thanks to Vincent St-Amour and Sam Tobin-Hochstadt for their tips on #racket | |
(define (words text) | |
(regexp-match* #rx"[a-z]+" (string-downcase text))) | |
(define (train features) | |
(define model (make-hash)) | |
(for ([f features]) |
This file contains 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
data Color = R | B | BB deriving (Show) | |
data Tree elt = E | EE | T Color (Tree elt) elt (Tree elt) deriving (Show) | |
type Set a = Tree a | |
empty = E | |
insert x s = blacken (ins s) | |
where insE=TRExE | |
ins (T color a y b) | x < y = balance color (ins a) y b |
This file contains 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 | |
(define (memoize proc) | |
(define memo '()) | |
(λ (x) | |
(cond [(assq x memo) => cdr] | |
[else (let ([result (proc x)]) | |
(set! memo (cons (cons x result) memo)) | |
result)]))) |
OlderNewer