Skip to content

Instantly share code, notes, and snippets.

@ypsilon-takai
Created September 12, 2011 04:55
Show Gist options
  • Save ypsilon-takai/1210614 to your computer and use it in GitHub Desktop.
Save ypsilon-takai/1210614 to your computer and use it in GitHub Desktop.
Support funcs for Google Code Jam
(require '[clojure.contrib.io :as io])
(defn get-gcj-args-list [file-name]
(map list
(iterate inc 1)
(map (fn [line-dat]
(map (fn [s] (BigInteger. s))
(.split line-dat " ")))
(drop 1 (io/read-lines file-name)))))
(defn get-gcj-args-list-ml [file-name line-count]
(map list
(iterate inc 1)
(partition line-count
(map (fn [line-dat]
(map (fn [s] (BigInteger. s))
(.split line-dat " ")))
(drop 1 (io/read-lines file-name))))))
(defn gcj-get-ans [file-name f]
(for [[num args] (get-gcj-args-list file-name)]
[num (apply f args)] ))
(defn gcj-get-ans-ml [file-name f line-num]
(for [[num args] (get-gcj-args-list-ml file-name line-num)]
[num (apply f args)] ))
(defn gcj-create-ans [in-file out-file f]
(with-open [bw (io/writer out-file)]
(io/with-out-writer bw
(dorun
(for [[num ans] (gcj-get-ans in-file f)]
(println (str "Case #" num ": " ans)))))))
(defn gcj-create-ans-ml [in-file out-file f line-num]
(with-open [bw (io/writer out-file)]
(io/with-out-writer bw
(dorun
(for [[num ans] (gcj-get-ans-ml in-file f line-num)]
(println (str "Case #" num ": " ans)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment