From 1415aea290225eff021551c15db542846feda437 Mon Sep 17 00:00:00 2001 From: leaen Date: Tue, 29 Oct 2019 08:20:12 +1100 Subject: [PATCH] Exercises for I am a horse in the land of booleans --- src/i_am_a_horse_in_the_land_of_booleans.clj | 33 +++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/i_am_a_horse_in_the_land_of_booleans.clj b/src/i_am_a_horse_in_the_land_of_booleans.clj index 66a18e7a..c8f9095e 100644 --- a/src/i_am_a_horse_in_the_land_of_booleans.clj +++ b/src/i_am_a_horse_in_the_land_of_booleans.clj @@ -2,27 +2,44 @@ (:refer-clojure :exclude [boolean])) (defn boolean [x] - ":(") + (if x true false)) (defn abs [x] - ":(") + (if (> x 0) + x + (- x))) (defn divides? [divisor n] - ":(") + (== (mod n divisor) 0)) (defn fizzbuzz [n] - ":(") + (cond + (divides? 15 n) "gotcha!" + (divides? 3 n) "fizz" + (divides? 5 n) "buzz" + :else "" + )) (defn teen? [age] - ":(") + (< 12 age 20)) (defn not-teen? [age] - ":(") + (not (teen? age))) (defn generic-doublificate [x] - ":(") + (cond + (number? x) (* 2 x) + (empty? x) nil + (or (list? x) (vector? x)) (* (count x) 2) + :else true + )) (defn leap-year? [year] - ":(") + (cond + (divides? 400 year) true + (divides? 100 year) false + (divides? 4 year) true + :else false + )) ; '_______'