Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; function that iterates over collection
- ; and multiplies elements by 2 or 3 if odd or even
- ; element
- (defn func1 [arr]
- (for [x arr] (* x (if (odd? x) 2 3))))
- ; function that iterates over collection and
- ; multiplies or divides elements by 2 if it is
- ; odd or even accordingly
- (defn func2 [arr]
- (for [x arr] ((if (odd? x) * /) x 2)))
- ; generating range
- (def a (range 20))
- ; curried function for subtract
- (defn sub [a]
- (fn [n] (- n a)))
- ; fibonacci function that returns fibonacci number by
- ; index in fibonacci requence
- (defn fib [n]
- (case n 0 0 1 1 2 1
- (+ (fib (dec n)) (fib ((sub 2) n)))))
- ; function for factorial
- (defn ! [n]
- (case n 0 1 1 1 (* n (! (dec n)))))
- (print (map ! a))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement