Last active
November 26, 2015 03:39
-
-
Save chrisguitarguy/db29412081e9fb721571 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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