Project Euler Problem 9

less than 1 minute read

Code

;; euler_9.clj

(def possibilities
  (for [a (range 1 1001) b (range (+ a 1) 1001)]
    [a b]))

(defn satisfies-condition [possibility]
  (let [a (first possibility)
        b (second possibility)
        c (- 1000 (+  a b))]
    (== (+ (* a a) (* b b)) (* c c))))

;; (filter satisfies-condition possibilities)

(let
 [[a b] (first (filter satisfies-condition possibilities))
  c (- 1000 (+ a b))]
  (* a b c))

Notes

Updated: