Advertisement
rabbiabram1

Untitled

Jun 11th, 2020
2,301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Enter your code here. Read input from STDIN. Print output to STDOUT
  2. ;
  3. (require '[clojure.string :as str])
  4.  
  5. (defn dis [a b]
  6.     (Math/sqrt (+ (Math/pow (- (first b) (first a)) 2) (Math/pow (- (second b) (second a)) 2)))
  7. )
  8.  
  9. (defn split-to-double [input]
  10.     (->> (str/split input #"\s")
  11.         (map #(Double/parseDouble %))
  12.         (into [])
  13.     )
  14. )
  15.  
  16. (defn get-points-vector [number-of-points]
  17.     (->> #(split-to-double (read-line))
  18.         (repeatedly number-of-points)
  19.         (into [])
  20.     )
  21. )
  22.  
  23.  
  24. (let [points (Integer/parseInt (read-line))
  25.     points_vector (get-points-vector points)
  26.     ]
  27.     (loop [x points_vector r 0]
  28.         (if (empty? (rest x))
  29.             (do
  30.                 (println (+ r (dis (first x) (first points_vector) )))          
  31.             )
  32.             (recur (rest x) (+ r (dis (first x) (second x))))
  33.         )
  34.     )
  35. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement