Skip to content

Instantly share code, notes, and snippets.

@monkeygroover
Created March 29, 2016 12:26
Show Gist options
  • Save monkeygroover/f824f6e75a4c806fbcbd to your computer and use it in GitHub Desktop.
Save monkeygroover/f824f6e75a4c806fbcbd to your computer and use it in GitHub Desktop.
euler23
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