From d033abaee2aadd7c325b07dbb8f3801f594087ac Mon Sep 17 00:00:00 2001 From: chao-fang Date: Tue, 31 May 2022 01:22:03 -0400 Subject: [PATCH] second assignment complete --- src/i_am_a_horse_in_the_land_of_booleans.clj | 31 ++++++++++++++------ 1 file changed, 22 insertions(+), 9 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..a98f0c6d 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,40 @@ (:refer-clojure :exclude [boolean])) (defn boolean [x] - ":(") + (not (or (nil? x) (false? x)))) (defn abs [x] - ":(") + (if (< x 0) + (- x) + x)) (defn divides? [divisor n] - ":(") + (= 0 (mod n divisor))) (defn fizzbuzz [n] - ":(") + (cond + (divides? 15 n) "gotcha!" + (divides? 5 n) "buzz" + (divides? 3 n) "fizz" + :else "")) (defn teen? [age] - ":(") + (> 20 age 12)) (defn not-teen? [age] - ":(") + (not (teen? age))) (defn generic-doublificate [x] - ":(") + (cond + (number? x) (* x 2) + (empty? x) nil + (or (list? x)(vector? x)) (* 2 (count x)) + :else true + )) (defn leap-year? [year] - ":(") + (or + (and (divides? 4 year) (not (divides? 100 year))) + (divides? 400 year))) + -; '_______'