From cdd46053a96d4215fb12ffa82114249da6b11e66 Mon Sep 17 00:00:00 2001 From: Kenneth Kostresevic Date: Thu, 16 Dec 2021 15:56:29 +0100 Subject: [PATCH] Solve recursion --- src/koans/14_recursion.clj | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/koans/14_recursion.clj b/src/koans/14_recursion.clj index ca29784..d108809 100644 --- a/src/koans/14_recursion.clj +++ b/src/koans/14_recursion.clj @@ -3,21 +3,27 @@ (defn is-even? [n] (if (= n 0) - __ - (___ (is-even? (dec n))))) + true + (not (is-even? (dec n))))) (defn is-even-bigint? [n] (loop [n n acc true] (if (= n 0) - __ + acc (recur (dec n) (not acc))))) (defn recursive-reverse [coll] - __) + (loop [coll coll acc '()] + (if (= coll []) + acc + (recur (rest coll) (conj acc (first coll)))))) (defn factorial [n] - __) + (loop [n n acc n] + (if (= n 1) + acc + (recur (dec n) (* acc (dec n)))))) (meditations "Recursion ends with a base case"