Skip to content

Instantly share code, notes, and snippets.

View camoy's full-sized avatar

Cameron Moy camoy

View GitHub Profile
@camoy
camoy / list.ml
Last active September 14, 2018 05:55
OCaml List Lecture (9/13/18)
(* Exercise: Write the class definition (no methods) for a linked list in
Java. *)
(* Bad Approach:
class List<T> {
T data;
List<T> next;
}
@camoy
camoy / z.ml
Created July 13, 2018 02:35
OCaml adapation of (Y Y) Works
(* This is an OCaml adaptation of (Y Y) Works! by Felleisen
and Friedman. An updated version of the same essay is
available in the Little Schemer, Chapter 9. To run the
examples you have to enable the -rectypes flag. *)
(* Let's define the length function. *)
let rec length xs =
match xs with
| [] -> 0
@camoy
camoy / reachability.hs
Last active June 20, 2018 04:50
Graph reachability in four lines of Haskell (requires set-monad package)
import qualified Data.Set.Monad as S
fix f init = until (\x -> x == f x) f init
close rstar = fix (\s -> s `S.union` (rstar s))
rstar g s = do { x <- s; (x, y) <- g; pure y }
reachable g = close (rstar g)
-- g1 = S.fromList [(1, 2), (2, 3), (3, 1), (4, 1)]
-- reachable g1 (S.singleton 1) == S.fromList [1, 2, 3]
@camoy
camoy / prize_box.md
Last active June 5, 2020 00:23
Solving a logic puzzle in Prolog.

A logic puzzle called "Prize Box" from the ASCM problem solving competition:

Three boxes, 3 signs: Only one box has the prize; n is odd if and only if two signs are true. Sign A says "n is even and box 1 has the prize." Sign B says "n + 4 is a multiple of 3 or box 3 has the prize." Sign C says "n is odd or box 2 has the prize." Given that n is a single digit positive integer where every digit is equally likely, which

@camoy
camoy / keybase.md
Created June 13, 2015 02:47
keybase.md

Keybase proof

I hereby claim:

  • I am camoy on github.
  • I am camoy (https://keybase.io/camoy) on keybase.
  • I have a public key whose fingerprint is CC10 FC49 A531 78CF 4DAA 0CAF 1CE9 059A 203F CAE1

To claim this, I am signing this object: