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
(define-syntax define-structure | |
(lambda (x) | |
(define construct-name | |
(lambda (template-identifier . args) | |
(datum->syntax | |
template-identifier | |
(string->symbol | |
(apply string-append | |
(map (lambda (x) | |
(if (string? x) |
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
;; Inspired by http://www.icsi.berkeley.edu/~nweaver/multitask.scm | |
(define (make-queue l r) | |
(cons l r)) | |
(define (queue-push queue val) | |
(make-queue (cons val (car queue)) | |
(cdr queue))) | |
(define (queue-pop queue) |
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
open Graphics | |
let (|+) (x1, y1) (x2, y2) = | |
x1 +. x2, y1 +. y2 | |
let (|-) (x1, y1) (x2, y2) = | |
x1 -. x2, y1 -. y2 | |
let (|*) s (x, y) = | |
s *. x, s *. y |
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
let vec_map f (x1, y1) (x2, y2) = | |
f x1 x2, f y1 y2 | |
let (|+) = vec_map (+.) | |
let (|-) = vec_map (-.) | |
let (|*) s (x, y) = | |
s *. x, s *. y |
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 Dict = | |
struct | |
type 'v t | |
external create : unit -> 'v t = "$new" "Object" | |
let add d k v = | |
Ocamljs.assign (Ocamljs.hashref d k) v | |
let find d k = | |
let v = Ocamljs.hashref d k in |
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 qualified Data.Set as Set | |
(x1, y1) |+ (x2, y2) = (x1+x2, y1+y2) | |
size = 8 | |
out_of_greed (x, y) = | |
let check v = v < 0 || v == size | |
in check x || check y |
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 qualified Data.Map as M | |
import Data.Map ((!)) | |
import Text.Printf | |
data Queue a = Queue [a] [a] | |
deriving Show | |
data Fork = Free | Used | |
deriving Show | |
type ForkMap = M.Map Int Fork |
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 OverloadedStrings #-} | |
import System.IO | |
import Network.Curl | |
import Network.URI | |
import Text.HTML.TagSoup | |
import Text.Printf | |
import Data.Graph.Inductive | |
import qualified Data.Map as M | |
import qualified Data.Set as S | |
import qualified Data.ByteString.Lazy as BS |
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
template <class T> | |
int ffs(T i) | |
{ | |
T step = sizeof(i)*8 >> 1; | |
int n = 1; | |
for (; step > 1; step >>= 1) { | |
T shift = ((T)1 << step)-1; | |
if (!(i & shift)) { | |
n += step; |
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
open OUnit | |
class printable_point x_init = | |
object (s) | |
val mutable x = x_init | |
method get_x = x | |
method move d = x <- x + d | |
method print = string_of_int s#get_x | |
end |
OlderNewer