Skip to content

Instantly share code, notes, and snippets.

@chrisguitarguy
Created March 8, 2017 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisguitarguy/d266ec54feca2809e9ce439a35ae6d7f to your computer and use it in GitHub Desktop.
Save chrisguitarguy/d266ec54feca2809e9ce439a35ae6d7f 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- parse-line [line]
(map str->int (string/split line #"\s+")))
(defn- positions [origin fruit]
(map #(+ origin %) fruit))
(defn- fruit-count [s t fruit]
(count
(filter #(and (>= % s)
(<= % t))
fruit)))
(defn run []
(let [[s t] (parse-line (read-line))
[apple-tree orange-tree] (parse-line (read-line))
[total-apples total-oranges] (parse-line (read-line))
apples (positions apple-tree (parse-line (read-line)))
oranges (positions orange-tree (parse-line (read-line)))]
(println (fruit-count s t apples))
(println (fruit-count s t oranges))))
(run)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment