**Find the only Pythagorean triplet which sums to get 1000**

A Pythagorean triplet consists of 3 numbers say x, y and z such that x < y < z and x^2 + y^2 = z^2.

The task is to find a triplet which satisfies the equation x + y + z = 1000

(defn sqr [x]
(* x x))
(defn triplets [n]
(loop [x 1 y 2 z (- n 3) acc '()]
(cond
(>= x z) acc
(>= y z) (recur (inc x) (+ 2 x) (- n (+ 3 x x)) acc)
:else (recur x (inc y) (dec z) (cons (list x y z) acc)))))

*triplets* generates all possible triplets (x, y, z) where x + y + z = 1000 and x < y < z

After this all that needs to be done is

(apply * (first (filter #(let [[a b c] %]
(= (+ (sqr a) (sqr b)) (sqr c)))
(triplets 1000)))

The *let* construct in this case has new syntax

(let [[a b c] '(1 2 3)]
(...))

This is known as destructuring, this syntax binds a, b and c to 1, 2 and 3 respectively.

### Like this:

Like Loading...

*Related*

Tad Clayton(12:16:37) :These two genetic combinations and hexagrams seem to be connected together under the influence of the Circuit Attractor / Consciousness, shown in the hypercube as North and South: and . Thus for consciousness you have to start from an understanding of the whole, the Wheel, and then turn to a single problem. In effect the mind has to be made holistic, balanced, put into equilibrium. This is accomplished for instance by PrimaSounds with its tuning to 12 hertz, or by a good night’s sleep with its full sequence of REM dreams. The Circuit Attractor with its conscious memories is then integrated into Being, leaving you free to act anew.