Skip to content

Instantly share code, notes, and snippets.

@Engelberg
Engelberg / Logic1.clj
Created March 7, 2013 05:49
Solving logic puzzle with for comprehension
(defn solve-logic-puzzle []
(let [people [:amaya :bailey :jamari :jason :landon]]
(first
(for [[fortune time cosmopolitan us-weekly vogue] (permutations people) ; magazines
[asiago blue-cheese mascarpone mozzarella muenster] (permutations people) ; cheeses
; We bind the reservations in two steps, so we have a name for the overall order
reservations (permutations people)
:let [[five six seven seven-thirty eight-thirty] reservations]
; THE CONSTRAINTS IN PLAIN ENGLISH
@Engelberg
Engelberg / SantaClaus.clj
Created February 19, 2013 18:47
Santa Claus problem in Clojure
;; Ref-based Santa Claus solution, Written by Mark Engelberg
;; (start-simulation) to run
(def *num-elves* 10)
(def *num-reindeer* 9)
;; Santa is a ref containing either {:state :asleep} or {:state :busy, :busy-with <sequence-of-workers>}
(def santa (ref {:state :asleep}))
(defn waiting-room [capacity]