@@ 1,16 1,26 @@
(ns interest-is-interesting)
+(defn abs [x]
+ (max x (- x)))
+
(defn interest-rate
- "TODO: add docstring"
+ "Select interest rate depending on balance amount."
[balance]
- )
+ (cond (neg? balance) -3.213
+ (< balance 1000) 0.5
+ (< balance 5000) 1.621
+ :else 2.475))
(defn annual-balance-update
- "TODO: add docstring"
+ "Calculate new balance after interest rate yield."
[balance]
- )
+ (let [rate (/ (bigdec (interest-rate balance)) 100)
+ delta (* (abs balance) rate)]
+ (+ balance delta)))
(defn amount-to-donate
- "TODO: add docstring"
+ "Donate twice the allowed governmental tax-free donation amount."
[balance tax-free-percentage]
- )>
\ No newline at end of file
+ (let [tax-free-pct (/ tax-free-percentage 100)
+ tax-free-donation-amount (max 0 (* balance tax-free-pct))]
+ (int (* 2 tax-free-donation-amount))))