# Finding Pythagorean triples

**URL:** <https://discourse.julialang.org/t/finding-pythagorean-triples/67954>\
**Category:** New to Julia\
**Created:** [September 9, 2021, 7:23pm UTC](https://discourse.julialang.org/t/finding-pythagorean-triples/67954 "2021-09-09T19:23:56Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [September 10, 2021, 2:15am UTC](https://discourse.julialang.org/t/finding-pythagorean-triples/67954/8 "2021-09-10T02:15:46Z")

</div>

Sure enough, it exists:

```nohighlight
julia> function find_next_imperfect_square(n)
           while true
               root = √n
               if isinteger(root) && Int(root)^2 != n
                   return n
               end
               n += 1
           end
       end
find_next_imperfect_square (generic function with 1 method)

julia> n = find_next_imperfect_square(2^52)
4503599627370497

julia> root = √n
6.7108864e7

julia> isinteger(root)
true

julia> Int(root)^2
4503599627370496

julia> Int(root)^2 == n
false

```

So there’s the true bound: `isinteger∘sqrt` will work for all n \< 4503599627370497. Didn’t take much time at all to find. Know what that number is? 🙂

---

_[View the full topic](https://discourse.julialang.org/t/finding-pythagorean-triples/67954)._
