public
Last active

clojure Dojo team 3

  • Download Gist
bankocr.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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
(ns bankocr.core)
 
(def parse {\space :., \_ :_, \| :|})
 
(defn parse-input [input] (map parse input ))
 
(def digits { [[:. :_ :.]
[:| :. :|]
[:| :_ :|]] 0
[[:. :. :.]
[:. :. :|]
[:. :. :|]] 1
[[:. :_ :.]
[:. :_ :|]
[:| :_ :.]] 2
[[:. :_ :.]
[:. :_ :|]
[:. :_ :|]] 3
[[:. :. :.]
[:| :_ :|]
[:. :. :|]] 4
[[:. :_ :.]
[:| :_ :.]
[:. :_ :|]] 5
[[:. :_ :.]
[:| :_ :.]
[:| :_ :|]] 6
[[:. :_ :.]
[:. :. :|]
[:. :. :|]] 7
[[:. :_ :.]
[:| :_ :|]
[:| :_ :|]] 8
[[:. :_ :.]
[:| :_ :|]
[:. :_ :|]] 9})
 
(def lines [" _ _ _ _ _ _ _ _ "
"| | | _| _||_||_ |_ ||_||_|"
"|_| ||_ _| | _||_| ||_| _|"] )
 
(defn partitioin-digits [lines]
(map #(partition 3 %) (map parse-input lines)))
 
(defn split-digits [digits]
(map vector (first digits) (second digits) (nth digits 2)))
 
(defn ocr [lines]
(map digits (split-digits (partitioin-digits lines))))

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.