Created
March 8, 2017 01:09
-
-
Save chrisguitarguy/d266ec54feca2809e9ce439a35ae6d7f 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- 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