Skip to content

Instantly share code, notes, and snippets.

@noprompt
Last active December 30, 2015 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noprompt/b07b85881d76c6ecba97 to your computer and use it in GitHub Desktop.
Save noprompt/b07b85881d76c6ecba97 to your computer and use it in GitHub Desktop.
(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