Skip to content

Instantly share code, notes, and snippets.

@chrisguitarguy
Last active November 26, 2015 03:39
Show Gist options
  • Save chrisguitarguy/db29412081e9fb721571 to your computer and use it in GitHub Desktop.
Save chrisguitarguy/db29412081e9fb721571 to your computer and use it in GitHub Desktop.
#!/usr/bin/env boot
(require '[clojure.string :as string])
(defn- str->int [s]
(Integer/parseInt s))
(defn- positive? [n]
(> n 0))
(defn- negative? [n]
(< n 0))
(defn- format-float [f]
(format "%.6f" (float f)))
(defn- filter-count [predicate collection]
(count (filter predicate collection)))
(defn -main [& args]
(let [expected-count (str->int (read-line))
nums (map str->int (string/split (read-line) #"\s+"))
actual-count (count nums)]
(assert (= expected-count actual-count)
(format "expected a collection of %d numbers, got %d" expected-count actual-count))
(println (format-float (/ (filter-count positive? nums) actual-count)))
(println (format-float (/ (filter-count negative? nums) actual-count)))
(println (format-float (/ (filter-count zero? nums) actual-count)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment