Permalink
Browse files

Booleans

  • Loading branch information...
1 parent e803953 commit 79d2099b0643c20e13826fed65147d625f535810 @MasseR committed Feb 21, 2014
Showing with 23 additions and 8 deletions.
  1. +23 −8 src/i_am_a_horse_in_the_land_of_booleans.clj
@@ -2,27 +2,42 @@
(:refer-clojure :exclude [boolean]))
(defn boolean [x]
- ":(")
+ (if x
+ true
+ false))
(defn abs [x]
- ":(")
+ (if (>= x 0)
+ x
+ (* -1 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]
- ":(")
+ (<= 13 age 19))
(defn not-teen? [age]
- ":(")
+ (not (teen? age)))
(defn generic-doublificate [x]
- ":(")
+ (cond
+ (number? x) (* 2 x)
+ (empty? x) nil
+ (or (vector? x) (list? x)) (* 2 (count x))
+ :else true))
(defn leap-year? [year]
- ":(")
+ (cond
+ (and (divides? 100 year) (divides? 400 year)) true
+ (and (divides? 4 year) (not (divides? 100 year))) true
+ :else false))
; '_______'

0 comments on commit 79d2099

Please sign in to comment.