我已提交了解决 bird watcher
问题的方案,测试套件抱怨它找不到 day-without-birds
函数。Visual Studio Code 能够从另一个文件导入并运行它。
解决方案的完整实现如下
解决方案
(ns bird-watcher)
(def last-week [0 2 5 3 7 8 4])
(defn last_position [v]
(- (clojure.core/count v) 1))
(defn today [birds]
(get birds (last_position birds)))
(defn inc-bird [birds]
(assoc birds (last_position birds) (+ (today birds) 1)))
(defn day-without-birds
[birds]
(loop [y birds]
(let [[x & rest] y]
(if (= x 0)
true
(if (empty? rest)
false
(recur rest))))))
(defn n-days-count [birds n]
(reduce + (take n birds)))
(defn busy [day]
(if (> day 5)
1
0))
(defn busy-days [birds]
(reduce + (map busy birds)))
(defn odd-week-internal
[birds x]
(loop [y birds
target x]
(let [[x & rest] y
target (- 1 target)]
(if (= x target)
(if (empty? rest)
true
(recur rest target))
false))))
(defn odd-week [birds]
(odd-week-internal birds 0))
提前感谢!