Finished koan 14
This commit is contained in:
parent
0d83f43cfd
commit
37bf3d22bf
4 changed files with 15 additions and 18 deletions
File diff suppressed because one or more lines are too long
|
|
@ -29,8 +29,7 @@
|
|||
(= 9 (((fn [] +)) 4 5))
|
||||
|
||||
"Functions can also take other functions as input"
|
||||
(= 20 ((fn [f] (f 4 5))
|
||||
*))
|
||||
(= 20 ((fn [f] (f 4 5)) *))
|
||||
|
||||
"Higher-order functions take function arguments"
|
||||
(= 25 ((fn [f] (f 5)) (fn [n] (* n n))))
|
||||
|
|
|
|||
|
|
@ -2,22 +2,20 @@
|
|||
(:require [koan-engine.core :refer :all]))
|
||||
|
||||
(defn is-even? [n]
|
||||
(if (= n 0)
|
||||
__
|
||||
(___ (is-even? (dec n)))))
|
||||
(if (= n 0) true (not (is-even? (dec n)))))
|
||||
|
||||
(defn is-even-bigint? [n]
|
||||
(loop [n n
|
||||
acc true]
|
||||
(if (= n 0)
|
||||
__
|
||||
(recur (dec n) (not acc)))))
|
||||
(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 newlist ()]
|
||||
(if (seq coll)
|
||||
(recur (rest coll) (conj newlist (first coll)))
|
||||
newlist)))
|
||||
|
||||
(defn factorial [n]
|
||||
__)
|
||||
(loop [n n acc 1]
|
||||
(if (= n 0) acc (recur (dec n) (* n acc)))))
|
||||
|
||||
(meditations
|
||||
"Recursion ends with a base case"
|
||||
|
|
|
|||
Loading…
Reference in a new issue