Skip to content

Instantly share code, notes, and snippets.

@PadraigK
Created December 21, 2024 00:54
Show Gist options
  • Save PadraigK/3239af1c75ea0e8b13b4e7e9d9bc987f to your computer and use it in GitHub Desktop.
Save PadraigK/3239af1c75ea0e8b13b4e7e9d9bc987f to your computer and use it in GitHub Desktop.
(ns bird-watcher)
(def last-week [0 2 5 3 7 8 4])
(defn today [birds]
(last birds))
(defn safe-last-index [v]
(if (empty? v)
nil ; or some appropriate value
(dec (count v))))
(defn inc-bird [birds]
(let [last-idx (safe-last-index birds)
new-count (inc (today birds))]
(assoc birds last-idx new-count)))
(defn day-without-birds? [birds]
(some? (some zero? birds)))
(defn n-days-count [birds n]
(apply + (take n birds)))
(defn busy-days [birds]
(count
(filter #(>= % 5) birds)))
(defn odd-week? [birds]
(= birds [1 0 1 0 1 0 1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment