functional-koans / clojure-koans

A set of exercises for learning Clojure
3.74k stars 2.14k forks source link

14 Recursion - is-even? #159

Closed zackteo closed 3 years ago

zackteo commented 3 years ago

Is it me or does the currently is-even? function seem wrong?

(defn is-even? [n]
  (if (= n 0)
    __
    (___ (is-even? (dec n)))))

Should it not be ...

(defn is-even? [n]
  (if (= (rem n 2) 0)
    true
    (not (is-even? (dec n)))))
zackteo commented 3 years ago

Whoops mistake. I understand why it works already