Skip to content

Instantly share code, notes, and snippets.

@nerdyworm
Created January 12, 2011 17:05
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 nerdyworm/776466 to your computer and use it in GitHub Desktop.
Save nerdyworm/776466 to your computer and use it in GitHub Desktop.
(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