Skip to content

Instantly share code, notes, and snippets.

@SegFaultAX
Created January 19, 2013 21:41
Show Gist options
  • Save SegFaultAX/4575386 to your computer and use it in GitHub Desktop.
Save SegFaultAX/4575386 to your computer and use it in GitHub Desktop.
Colossal Cue Solutions
(defn vax-rand [seed]
(mod (inc (* 69069 seed)) (Math/pow 2 32)))
(defn vax-seq [seed]
(iterate vax-rand seed))
(defn roulette [n seed m]
(take n (map #(int (mod % m)) (vax-seq seed))))
;; Level 1 solution
(roulette 10 6 36)
(def open-bracket #{\( \[ \{})
(def closed-bracket #{\) \] \}})
(def matched-pair {\( \), \[ \], \{ \}})
(defn check-pairs
([s] (check-pairs (seq s) () 0))
([[b & more] [top & bot :as stack] idx]
(when b
(cond
(open-bracket b) (recur more (conj stack b) (inc idx))
(and (closed-bracket b)
(= b (matched-pair top))) (recur more bot (inc idx))
:else idx))))
;; Level 2 solution
(check-pairs "[}")
(check-pairs "({})}()")
(check-pairs "{{[{{{{}}{{}}}[]}[][{}][({[(({{[][()()]}}{[{{{}}}]}))][()]{[[{((()))({}(())[][])}][]()]}{()[()]}]})][]]}{{}[]}}")
;; Level 3 is small enough to solve manually, but I'll probably add a solver later.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment