Created
January 12, 2011 17:05
-
-
Save nerdyworm/776466 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 topfive.topfive | |
(:import | |
(java.io BufferedReader FileReader) | |
(java.util Hashtable))) | |
(def filename | |
(if (nil? *command-line-args*) | |
(str "topfive/topfive-a.in") | |
(first *command-line-args*))) | |
(defn process-file [file-name] | |
(let [histogram (new Hashtable)] | |
(with-open [rdr (BufferedReader. (FileReader. file-name))] | |
(doseq [line (line-seq rdr)] | |
(let [query (second (re-find #"query=(.+)]" line))] | |
(if (.get histogram query) | |
(.put histogram query (inc (.get histogram query))) | |
(.put histogram query 1))))) histogram)) | |
(time (let [results (process-file filename)] | |
(doseq [top (take 5 (sort-by #(.get results %) > (keys results)))] | |
(println top)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment