Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Pythagorean Triples

  • 31-12-2010 04:27AM
    #1
    Registered Users, Registered Users 2 Posts: 218 ✭✭


    I want to generate a list of all primitive pythagorean triples limited by perimeter.
    To generate triples I can use the formula:
    (a, b, c) = (m^2 - n^2, 2mn, m^2 + n^2)
    where m > n, m and n are coprime and m or n are even.
    

    Perimeter = a + b + c = 2m(m + n)
    ptriples p      = [(m^2-n^2, 2*m*n, m^2+n^2) |
                            n <- [1..??],
                            m <- [n+1, n+3..??],
                            coprime m n,
                            2 * m * (m + n) < p]
    
    (sorry about the code, I don't know the mathematical notation)
    How do I work out the upper bounds of m and n ("??" above)?


    Edit (think I figured out m):
    a + b + c = p
    max c = p/2
    c = m^2 + n^2
    p/2 = m^2 + n^2
    max m when n = 1
    max m = floor (sqrt (p/2 - 1))

    Does this make sense?


Advertisement