Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

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