-
-
Save noprompt/b07b85881d76c6ecba97 to your computer and use it in GitHub Desktop.
This file contains 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
(ns bank-ocr.core | |
(:require [clojure.set :as set] | |
[clojure.java.io :as io])) | |
;; SEE: http://codingdojo.org/cgi-bin/wiki.pl?KataBankOCR | |
(def top | |
{" " #{1 4} | |
" _ " #{0 2 3 5 6 7 8 9}}) | |
(def middle | |
{"| |" #{0} | |
" |" #{1 7} | |
" _|" #{2 3} | |
"|_|" #{4 8 9} | |
"|_ " #{5 6}}) | |
(def bottom | |
{" |" #{1 4 7} | |
"|_ " #{2} | |
" _|" #{3 5 9} | |
"|_|" #{0 6 8}}) | |
(defn parse-number [[t m b]] | |
(->> [(top t) (middle m) (bottom b)] | |
(reduce set/intersection) | |
first)) | |
(defn read-account-number [file-lines] | |
(->> (take 3 file-lines) | |
(map #(re-seq #"..." %)) | |
(apply interleave) | |
(partition 3) | |
(reduce | |
(fn [number parts] | |
(str number (or (parse-number parts) \?))) | |
""))) | |
(defn read-account-numbers [file] | |
(->> (io/file file) | |
io/reader | |
line-seq | |
(partition-all 4) | |
(map read-account-number))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment