Skip to content

Instantly share code, notes, and snippets.

@rabbiabram
Created June 10, 2020 08:20
Show Gist options
  • Select an option

  • Save rabbiabram/6612f997f859b8c64ac277befdcf0c40 to your computer and use it in GitHub Desktop.

Select an option

Save rabbiabram/6612f997f859b8c64ac277befdcf0c40 to your computer and use it in GitHub Desktop.
; Enter your code here. Read input from STDIN. Print output to STDOUT
;
(require '[clojure.string :as str])
;; (defn )
(defn read_split [] (map #(Long/parseLong %) (-> (read-line)
(str/split #" "))))
(defn calc [coefs pows f x]
(let [cp (zipmap coefs pows)]
(reduce-kv (fn [r a b]
(+ r (f (* a (Math/pow x b))))
) 0 cp)
)
)
(defn rotate [x]
(* x x)
)
(defn area_calc [delta]
(fn [x] x)
)
(let [a_n (read_split)
b_n (read_split)
[L R] (read_split)
delta 0.001
]
(let [
sum (reduce + (->> (range L (+ R delta) delta) (map #(calc a_n b_n (fn [x] x) %))))
area (reduce + (->> (range L (+ R delta) delta) (map #(calc a_n b_n rotate %))))
]
(println (* delta sum))
(println (* delta (* Math/PI area)))
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment