2024 Clojure状态调查!上发表你的看法。

欢迎!请参阅关于页面以获取更多有关此如何工作的信息。

0 投票
门户

我提交了对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))

提前感谢!

此问题依赖于没有明确说明的一些信息。"已提交" - 究竟在哪里?此外,请注意,你在“门户”部分提出了此问题,但我看不出门户与问题的相关性。

登录注册以回答此问题。

...