Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task02: Horse in the Land of Booleans #1640

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ pom.xml
.lein-deps-sum
.lein-failures
.lein-plugins
/.clj-kondo
/.lsp
102 changes: 102 additions & 0 deletions .lein-repl-history
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
(use 'i-am-a-horse-in-the-land-of-booleans)
boolean true
boolean false
boolean ""
(boolean "")
(boolean nil)
(boolean (+ 2 3))
(use 'i-am-a-horse-in-the-land-of-booleans)
(teen? 13)
(teen? 12)
(teen? 19)
(teen? 20)
(teen? 18)
(teen? 17)
(teen? 16)
(use 'i-am-a-horse-in-the-land-of-booleans)
(abs -2)
(load-file "i_am_a_horse_in_the_land_of_booleans.clj"
)
(load-file "i_am_a_horse_in_the_land_of_booleans.clj")
(use 'i-am-a-horse-in-the-land-of-booleans)
(abs -4)
(abs -42)
(abs 34)
(use 'i-am-a-horse-in-the-land-of-booleans)
(divides? 2 4 )
(divides? 4 2 )
(divides? 5 10)
(divides? 2 5)
(use 'i-am-a-horse-in-the-land-of-booleans)
(fizzbuzz 2)
(fizzbuzz 45)
(use 'i-am-a-horse-in-the-land-of-booleans)
(fizzbuzz 45)
(fizzbuzz 2)
(fizzbuzz 48)
(use 'i-am-a-horse-in-the-land-of-booleans)
(fizzbuzz 48)
(fizzbuzz 70)
number? ""
number? 3
(number "")
(number? "")
(use 'i-am-a-horse-in-the-land-of-booleans)
(generic-doublificate 1)
(generic-doublificate [1 2])
(use 'i-am-a-horse-in-the-land-of-booleans)
(generic-doublificate [1 2])
(use 'i-am-a-horse-in-the-land-of-booleans)
(generic-doublificate [1 2])
(use 'i-am-a-horse-in-the-land-of-booleans)
(generic-doublificate [1 2])
(generic-doublificate '{65 21})
(use 'i-am-a-horse-in-the-land-of-booleans)
(generic-doublificate '{65 21})
(generic-doublificate [1 2])
(use 'i-am-a-horse-in-the-land-of-booleans)
(generic-doublificate [1 2])
(generic-doublificate '{65 21})
(generic-doublificate '(65 21))
(use 'i-am-a-horse-in-the-land-of-booleans)
(generic-doublificate '(65 21))
(use 'i-am-a-horse-in-the-land-of-booleans)
(generic-doublificate '(65 21))
(use 'i-am-a-horse-in-the-land-of-booleans)
(generic-doublificate '(65 21))
(generic-doublificate [1 2])
(generic-doublificate {})
(generic-doublificate [])
(type {})
(empty? {})
(type '())
(type [])
(use 'i-am-a-horse-in-the-land-of-booleans)
(generic-doublificate {})
(generic-doublificate [1 2])
(generic-doublificate {:a 1})
(use 'i-am-a-horse-in-the-land-of-booleans)
(generic-doublificate {:a 1})
(generic-doublificate [1 2])
(generic-doublificate {})
(generic-doublificate '(65 21))
(generic-doublificate [])
(generic-doublificate 1)
(and "doo" false)
(and "doo" true)
(and 43 true)
(or 43 true)
(and true true false nil)
(mod 4 2)
(mod 2 4)
(mod 30 4)
(mod 30 1)
(mod 1 30)
(use 'i_am_a_horse_in_the_land_of_booleans.clj)
(use 'i-am-a-horse-in-the-land-of-booleans)
(leap-year? 100)
(leap-year? 200)
(leap-year? 400)
(leap-year? 12)
(leap-year? 20)
(leap-year? 15)
30 changes: 22 additions & 8 deletions src/i_am_a_horse_in_the_land_of_booleans.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,41 @@
(:refer-clojure :exclude [boolean]))

(defn boolean [x]
":(")
(if (or (= x nil) (= x false))
false
true))

(defn abs [x]
":(")
(if (< x 0) ( * -1 x) x))

(defn divides? [divisor n]
":(")
(if (== (mod n divisor) 0) true false))

(defn fizzbuzz [n]
":(")
(cond
(divides? 15 n) "gotcha!"
(divides? 5 n) "buzz"
(divides? 3 n) "fizz"
:else ""))

(defn teen? [age]
":(")
(if (< 12 age 20) true false))

(defn not-teen? [age]
":(")
(not (teen? age)))

(defn generic-doublificate [x]
":(")
(cond
(number? x) (* x 2)
(and (seqable? x) (empty? x)) nil
(or (list? x) (vector? x)) (* 2 (count x))
:else true))

(defn leap-year? [year]
":(")
(cond
(divides? 400 year) true
(divides? 100 year) false
(divides? 4 year) true
:else false))

; '_______'