there is this exercism exercise:
Given an input integer N, find all Pythagorean triplets for which
a + b + c = N
.
For example, with N = 1000, there is exactly one Pythagorean triplet
for whicha + b + c = 1000
:{200, 375, 425}
.
[Pythagorean Triplet in Elixir on Exercism]
I wonder if I should optimize the ranges here:
for a <- 1..sum,
b <- (a + 1)..sum,
c = sum - a - b,
c > b,
triplet = [a, b, c],
pythagorean?(triplet) do
triplet
end
for example I could use a..div(sum/2)
. Or does the compiler (using the filter c > b
) optimize this?
I understand, that everything after the filter will not be executed (if the filter is falsy), the question is if the stuff before gets optimized away.