Created
December 21, 2024 00:54
-
-
Save PadraigK/3239af1c75ea0e8b13b4e7e9d9bc987f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(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