secret
Last active

august clojure dojo mucking-about

  • Download Gist
gistfile1.clj
Clojure
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
; http://codingdojo.org/cgi-bin/wiki.pl?KataBankOCR
 
(ns baclj
(:use [clojure.string :only [split]]))
 
(def digits [
" _ _ _ _ _ _ _ "
" | _| _||_||_ |_ ||_||_|"
" ||_ _| | _||_| ||_| _|"])
 
(def input
(partition 4 (split (slurp "numbers.txt") #"\n")))
 
(println (count input))
 
(defn nth-digit [lines n]
"0-indexed."
(let [x (* 3 n) x2 (+ 3 x)]
(for [y (range 3)] (subs (nth lines y) x x2))))
 
(def digit-map
(into {} (for [i (range 9)] [(nth-digit digits i) (+ 1 i)])))
 
; (doall
; (for [i (range 9)]
; (let [joined (interpose "\n" (nth-digit digits i))]
; (println (apply str joined)))))
 
(doseq [part input]
(doall (map println part))
(println
(apply str
(for [i (range 9)] (digit-map (nth-digit part i))))
))

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.