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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Pythagorean Triples

  • 31-12-2010 3: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