Skip to content

Instantly share code, notes, and snippets.

@ponkore
Created April 26, 2012 12:29
Show Gist options
  • Save ponkore/2499257 to your computer and use it in GitHub Desktop.
Save ponkore/2499257 to your computer and use it in GitHub Desktop.
Project Euler Problem 9
;;; A Pythagorean triplet is a set of three natural numbers, a b c, for which,
;;; a^2 + b^2 = c^2
;;; For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
;;; There exists exactly one Pythagorean triplet for which a + b + c = 1000.
;;; Find the product abc.
(defn problem9 [limit]
(let [lazy-seq (take limit (iterate inc 1))]
(for [a lazy-seq b lazy-seq c lazy-seq
:when (and (= (+ (* a a) (* b b)) (* c c))
(= (+ a b c) 1000))]
[:a a :b b :c c :product (* a b c)])))
(problem9 500)
;;;=> [:a xxx :b xxx :c xxx :product xxx(ans)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment