-
-
Save levity/fe6844b82d698ee2dd08 to your computer and use it in GitHub Desktop.
august clojure dojo mucking-about
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
; 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)))) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment