Created
January 19, 2013 21:41
-
-
Save SegFaultAX/4575386 to your computer and use it in GitHub Desktop.
Colossal Cue Solutions
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
(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