You are viewing a single comment's thread. Return to all comments →
Clojure:
(use ['clojure.string :only '(split)]) (defn str-to-ints [string] (map #(Integer/parseInt %) (split string #" "))) (defn get-sides [coords] (conj (partition 2 1 coords) (list (first coords) (last coords)))) (defn side-length [side] (let [ a (first side) b (second side)] (Math/sqrt (+ (Math/pow (- (first a) (first b)) 2) (Math/pow (- (second a) (second b)) 2))) ) ) (defn read-input [] (doall (line-seq (java.io.BufferedReader. *in*)))) (->> (read-input) (rest) (map str-to-ints) (get-sides) (map side-length) (reduce +) (println) )
Seems like cookies are disabled on this browser, please enable them to open this website
Compute the Perimeter of a Polygon
You are viewing a single comment's thread. Return to all comments →
Clojure: