diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2021-06-19 12:17:16 +0200 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2021-06-19 12:17:16 +0200 |
| commit | 16a3e5fc6728f1c0d414983f6e1fc3fc160034b3 (patch) | |
| tree | 2dc9ba1f40d96378040f60ed36fa589c3e81b566 /julia/009-special_pythagorean_triplet.jl | |
| parent | 51464d5a71c4550683940db2753c50db0569bc17 (diff) | |
| download | project_euler-16a3e5fc6728f1c0d414983f6e1fc3fc160034b3.tar.gz project_euler-16a3e5fc6728f1c0d414983f6e1fc3fc160034b3.tar.bz2 project_euler-16a3e5fc6728f1c0d414983f6e1fc3fc160034b3.zip | |
problem 8 9 10 in julia
Diffstat (limited to 'julia/009-special_pythagorean_triplet.jl')
| -rw-r--r-- | julia/009-special_pythagorean_triplet.jl | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/julia/009-special_pythagorean_triplet.jl b/julia/009-special_pythagorean_triplet.jl new file mode 100644 index 0000000..65404be --- /dev/null +++ b/julia/009-special_pythagorean_triplet.jl @@ -0,0 +1,27 @@ +### +# Special Pythagorean triplet +# Problem 9 +# +# A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, +# a2 + b2 = c2 +# For example, 32 + 42 = 9 + 16 = 25 = 52. +# There exists exactly one Pythagorean triplet for which a + b + c = 1000.Find the product +# abc. +### + + +using Base.Iterators + + +for c in countfrom(1) + for b in 1:(c - 1) + for a in 1:(b - 1) + if a ^ 2 + b ^ 2 == c ^ 2 && a + b + c == 1000 + println(a * b * c) + exit(0) + end + end + end +end + + |
