Skip to content

Instantly share code, notes, and snippets.

@kaz-yos
Created August 14, 2015 11:32
Show Gist options
  • Save kaz-yos/9f10791faf924daa7f55 to your computer and use it in GitHub Desktop.
Save kaz-yos/9f10791faf924daa7f55 to your computer and use it in GitHub Desktop.
;;; my naive solution to clojure puzzle at
;;; Boston Clojure meetup on 8/14/2015
;;; http://www.meetup.com/Boston-Clojure-Group/events/224014745/?a=uc1_te&_af=event&_af_eid=224014745
(def bosclj-data
[[:b 7 2 1 2 2 2 1 2 1 2 7]
[:b 1 5 1 3 3 1 3 2 2 1 1 5 1]
[:b 1 1 3 1 1 1 3 1 3 1 1 3 1 1 1 1 3 1 1]
[:b 1 1 3 1 1 2 3 1 3 2 2 2 1 1 3 1 1]
[:b 1 1 3 1 1 3 1 3 1 2 3 2 1 1 3 1 1]
[:b 1 5 1 2 1 3 1 3 1 1 1 2 1 5 1]
[:b 7 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 7]
[:w 8 3 1 3 1 2 1 1 9]
[:b 3 1 5 1 2 2 4 1 4 3 1 2]
[:w 4 1 2 1 2 2 2 2 1 2 1 1 1 1 2 1 2 1]
[:b 1 1 1 1 1 1 4 3 1 2 1 4 2 1 1 1 3]
[:b 1 1 1 5 1 2 1 5 1 2 2 5 1 1]
[:b 2 1 4 1 1 3 1 2 3 1 5 1 1 1 2]
[:b 1 1 2 1 1 1 1 3 3 2 2 3 2 2 1 2 1]
[:w 1 4 1 3 2 2 1 1 1 1 1 1 2 2 3 1 2]
[:b 1 1 2 1 1 4 1 1 9 2 3 1 1 1]
[:w 1 1 1 1 1 4 2 1 2 4 1 4 2 1 1 2]
[:w 1 1 2 2 1 1 1 3 2 1 1 2 2 1 1 1 2 2 1 1]
[:b 1 1 1 1 4 5 1 3 1 4 2 3 2]
[:w 1 1 3 1 2 1 2 1 5 2 1 3 2 1 1 1 1]
[:b 1 2 4 5 1 3 9 4]
[:w 8 2 1 3 2 1 2 2 3 1 1 3]
[:b 7 1 2 1 2 1 1 2 1 1 2 1 1 1 2 1 2]
[:b 1 5 1 1 3 1 3 2 2 1 1 3 2 1 2]
[:b 1 1 3 1 1 1 1 2 1 2 1 2 1 2 5 3 1]
[:b 1 1 3 1 1 4 1 2 1 1 2 2 2 2 1 1 3]
[:b 1 1 3 1 1 1 1 1 1 2 1 3 2 1 1 2 3 2 1]
[:b 1 5 1 1 1 2 1 4 2 1 2 1 2 3 1 1]
[:b 7 1 1 1 1 1 1 2 3 1 2 2 3 1 2]])
(defn rep [s n]
"R-like rep"
(take n (repeat s)))
(= (rep "k" 5)
["k" "k" "k" "k" "k"])
;;; What each row add up to
(->> bosclj-data
(map rest)
(map #(reduce + 0 %)))
;;; Length of each row
(->> bosclj-data
(map rest)
(map count))
;;; The length
(count bosclj-data)
;;; Take initial letter
(->> bosclj-data
(map first))
;;; Define functions that return 0,1 sequence
(defn bw [n] (take n (reduce concat (take n (repeat ["1" "0"])))))
(defn wb [n] (take n (reduce concat (take n (repeat ["0" "1"])))))
;;; Function to return either one depending on first color
(defn seq-col [col]
(case col
:b bw
:w wb))
((seq-col :b) 3)
(reduce concat (map rep ((seq-col :b) 3) [1 2 3]))
(def a-row [:b 7 1 1 1 1 1 1 2 3 1 2 2 3 1 2])
(defn row-to-col-seq [row]
(let [fst (first row)
rst (rest row)
n (count rst)
seq-col-1 ((seq-col fst) n)]
;;
(->> (reduce concat (map rep seq-col-1 rst))
(clojure.string/join ""))))
(row-to-col-seq a-row)
(def seq-rows-coded (map row-to-col-seq bosclj-data))
;;; one big string with \n in between
(def one-str (clojure.string/join "\n" seq-rows-coded))
(print one-str)
(print (str "P1\n29\n29\n" one-str))
(spit "./src/puzzle/out.pbm" (str "P1\n29\n29\n" one-str))
;;; Then (imagemagick) convert out.pbm out.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment