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:
I hereby claim:
To claim this, I am signing this object:
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
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] |
(* 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 |
(* Exercise: Write the class definition (no methods) for a linked list in | |
Java. *) | |
(* Bad Approach: | |
class List<T> { | |
T data; | |
List<T> next; | |
} | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
(define (assert pred) | |
(or pred (amb))) | |
(define amb-queue (make-parameter #f)) | |
(define amb-escape (make-parameter #f)) | |
(define-syntax-rule (begin-amb fail body ...) | |
(let/cc k |
(define-values (success-tag fail-tag) | |
(values (make-continuation-prompt-tag 'success) | |
(make-continuation-prompt-tag 'fail))) | |
(define-syntax amb | |
(syntax-rules () | |
[(_ alt ...) | |
(call/comp | |
(λ (k) | |
(abort |
let with_return f x = | |
let r = ref None in | |
try | |
f (fun v -> r := (Some v); raise Not_found) x | |
with _ -> | |
match !r with | |
| None -> raise Not_found | |
| Some x -> x | |
let til_first_even = |
#lang racket/base | |
(require racket/contract) | |
(define must-return/c | |
(make-contract | |
#:name 'must-return/c | |
#:late-neg-projection | |
(λ (blm) | |
(λ (f neg) |
#lang racket/base | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; provide | |
(provide violin) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; require |