Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: adding array elements

by Fletch (Chancellor)
on Mar 09, 2011 at 17:03 UTC ( #892238=note: print w/ replies, xml ) Need Help??


in reply to adding array elements

;; 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.


Comment on Re: adding array elements
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://892238]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (18)
As of 2015-07-01 17:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (14 votes), past polls