Created
March 29, 2016 12:26
-
-
Save monkeygroover/f824f6e75a4c806fbcbd to your computer and use it in GitHub Desktop.
euler23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type DivisorType = Deficient | Perfect | Abundant | |
let divisors number = {1 .. number/2} |> Seq.filter(fun n -> number % n = 0) | |
let sumDivisors = divisors >> Seq.sum | |
let divisorSumType number = match (number - sumDivisors number) with | |
| 0 -> Perfect | |
| d when d > 0 -> Deficient | |
| d -> Abundant | |
let abundants = [1..28123] |> List.filter(fun n -> divisorSumType n = Abundant) | |
let abundantPairs = Set.ofSeq <| seq { for x in abundants do | |
for y in abundants -> x + y } | |
let result = {1..28123} | |
|> Seq.filter(fun n -> not <| abundantPairs.Contains n) | |
|> Seq.sum | |
printfn "%A" result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment