;; Presented with just about as much Perl as the OP . . . (ns sumcols (:use [clojure.contrib.str-utils :only (re-split)]) (:use [clojure.contrib.duck-streams :only (read-lines)])) (defn sumline [acc line] (loop [a acc l (map #(Float. %) (re-split #"\s+" line)) idx 0] (if (empty? l) a (recur (assoc a idx (+ (get a idx 0) (first l))) (rest l) (inc i +dx))))) (defn sumcols [filename] (loop [acc {} lines (filter #(> (count %) 0) (read-lines filename))] (if (empty? lines) (vals acc) (recur (sumline acc (first lines)) (rest lines))))) (println (sumcols (first *command-line-args*)))
The cake is a lie.
The cake is a lie.
The cake is a lie.
In reply to Re: adding array elements
by Fletch
in thread adding array elements
by Sidac
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |