Created
April 24, 2012 11:49
-
-
Save svdberg/2479040 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 googlecodejam | |
[:use clojure.string]) | |
(def example-input ["ejp mysljylc kd kxveddknmc re jsicpdrysi" | |
"rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd" | |
"de kr kd eoya kw aej tysr re ujdr lkgc jv"]) | |
(def google ["our language is impossible to understand" | |
"there are twenty six factorial possibilities" | |
"so it is okay if you want to just give up"]) | |
;; | |
;;we need to create a map from input to google and vice versa | |
;; | |
(defn create-mapping | |
[i g] | |
(->> | |
(map #(map (fn [ii gg] (hash-map ii gg)) %1 %2) i g) | |
flatten | |
(apply merge))) | |
;; | |
;; add the manual stuff ourselves | |
;; | |
(def dict (assoc (create-mapping example-input google) \z \q)) | |
(defn translate | |
[dict in-string] | |
(->> (map #(dict %) in-string) | |
(apply str))) | |
(def input (-> "/Users/svdberg/Documents/Projects/Clojure/A-small-practice.in.txt" slurp clojure.string/split-lines)) | |
(doseq [[idx txt] (map #(vector %1 %2) (range) input)] | |
(println (str "Case #" (inc idx) ": " (translate dict txt)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment