Skip to content

Instantly share code, notes, and snippets.

@ElemarJR
Last active September 3, 2015 18:48
Show Gist options
  • Select an option

  • Save ElemarJR/ec912edd38ac0e740943 to your computer and use it in GitHub Desktop.

Select an option

Save ElemarJR/ec912edd38ac0e740943 to your computer and use it in GitHub Desktop.
(* --- 0001 --- *)
[1..999]
|> List.where (fun f -> (f % 3 = 0) || (f % 5 = 0))
|> List.sum
(* --- 0002 --- *)
let fib =
let rec f a b = seq {
yield a
yield! f b (a + b)
}
f 0 1
fib
|> Seq.takeWhile (fun n -> n < 4000000)
|> Seq.where (fun n -> n % 2 = 0)
|> Seq.sum
(* --- 0003 --- *)
let ub n = int64 (sqrt(double(n)))
let factorsOf n =
[2L..ub(n)] |> Seq.filter (fun x -> n % x = 0L)
let isPrime n = factorsOf(n) |> Seq.length = 0
let findMaxPrimeFactorOf n =
[2L..ub(n)]
|> Seq.filter (fun x -> n % x = 0L)
|> Seq.filter isPrime
|> Seq.max
let maxPrime = findMaxPrimeFactorOf(600851475143L)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment