Advertisement
zvoulgaris

Pythagorean Quadruples

Feb 25th, 2020
2,922
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 0.50 KB | None | 0 0
  1. # Pythagorean quadruples drill
  2.  
  3. function IsSquare(n::Int64)
  4.     sn = round(Int64, sqrt(n))
  5.     return sn^2 == n, sn
  6. end
  7.  
  8. function CountQuadruples(N::Int64, verbose::Bool = false)
  9.     z = 0
  10.  
  11.     for a = 1:N
  12.         for b = a:N
  13.             for c = b:N
  14.                 flag, d = IsSquare(a^2 + b^2 + c^2)
  15.  
  16.                 if flag
  17.                     z += 1
  18.                     if verbose; println((a,b,c,d)); end
  19.                 end
  20.             end
  21.         end
  22.     end
  23.  
  24.     return z
  25. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement