On Thu, 2010-04-22 at 22:29 +0700, Per Vognsen wrote:
> How about this?
>
> (use 'clojure.contrib.str-utils 'clojure.contrib.duck-streams)
>
> (defn parse [file]
> (let [r (reader file)]
> (map (fn [line] (map #(Integer/parseInt %) (.split line " ")))
> (take (Integer/parseInt (
I really hate how GMail line wraps without giving you a chance to
preview before sending.
Here's a version of parse that shouldn't line wrap. It also more
closely parallels unparse by using for instead of map:
(defn parse [file]
(let [r (reader file)]
(for [line (take (Integer/parseInt (.re
You'll want to take a look at the docs for c.c.string[1], so have that
open in another tab. Anyway, let's assume you have the data in a file
mytext.txt
First, load the raw data with the slurp fn
user=>(def raw-string (slurp "mytext.txt"))
Next, you'll want to use the split-lines fn to create a
How about this?
(use 'clojure.contrib.str-utils 'clojure.contrib.duck-streams)
(defn parse [file]
(let [r (reader file)]
(map (fn [line] (map #(Integer/parseInt %) (.split line " ")))
(take (Integer/parseInt (.readLine r)) (repeatedly
#(.readLine r))
(defn unparse [xss file
Hi!
I'm learning Clojure and trying some Google Code Jam exercises.
I am more or less satisfied with the style of algorithms I write, but
I would like to know how to do input/output. I want it to be Clojure
style (terse/functional/efficient) not just rewriting the usual
loops...
Take a look at simp