Friday, June 18, 2010

Problem 39: For which value of p ≤ 1000, is the number of solutions maximised?

Brute force algorithm with no real optimizations.

let problem39c =
    let countTriplets p = 
        let mutable count = 0
        for a in 1..p do
            for b in a..p do
                let c = p - (a + b) |> float
                let c' = a*a + b*b |> float |> sqrtF
                if c = c' then
                    count <- count + 1
        count
        
    {1..1000}
    |> PSeq.maxBy countTriplets

No comments:

Post a Comment