Greatest of three numbers in Clojure

less than 1 minute read

Code

;; greatest_of_three_numbers.clj

(def a 27)
(def b 20)
(def c 25)

(if (> a b)
  (if (> a c)
    a
    c)
  (if (> b c)
    b
    c))

(if (> a b) (if (> a c) a c) (if (> b c) b c))

(if (and (> a b) (> a c)) a (if (and (> b a) (> b c)) b c))

(first (sort > [a b c]))

(max a b c)

(reduce max [a b c])

(apply max [a b c])

;; (max [a b c]) ; doesnt work right

(max a (max b c))

;; (if (> a b c) a (if (> b c) b c)) ; doesn't work for a > b and a < c

Updated: