Hello! Thank you for your contribution to polyglot-euler.
[ā ] I checked CONTRIBUTING.md for my programming language of choice.
How the solution works
Clojure doesn't have its own numeric tower, so we have to define square and sqrt (the later returns a float)
sum-1000? is a predicate that checks if a group of 3 numbers sums 1000 (using == instead of = ignores "type"; (= 1 1.0) is false, but (== 1 1.0) is true)
candidates is a lazy sequence of 3-vectors of numbers, built from ranges.
5 < b <= 700 ; heuristics alert: 700 is a reasonable number to start our search, and we know b can't be smaller than say, 5. in the code its reverses so we start looking from 700.
4 <= a < b ;
and c is defined as ā(a^2 + b^2)
then we keep only the vectors that pass our sum-1000? test, turn them to ints (to keep sure we don't print anything in "scientific notation" and get their product.
Hello! Thank you for your contribution to
polyglot-euler
.How the solution works
Clojure doesn't have its own numeric tower, so we have to define
square
andsqrt
(the later returns a float)sum-1000?
is a predicate that checks if a group of 3 numbers sums 1000 (using==
instead of=
ignores "type";(= 1 1.0)
isfalse
, but(== 1 1.0)
istrue
)candidates
is a lazy sequence of 3-vectors of numbers, built from ranges. 5 < b <= 700 ; heuristics alert: 700 is a reasonable number to start our search, and we know b can't be smaller than say, 5. in the code its reverses so we start looking from 700. 4 <= a < b ; and c is defined as ā(a^2 + b^2)then we keep only the vectors that pass our
sum-1000?
test, turn them to ints (to keep sure we don't print anything in "scientific notation" and get their product.Performance
Try it online!