Last active
September 3, 2015 18:48
-
-
Save ElemarJR/ec912edd38ac0e740943 to your computer and use it in GitHub Desktop.
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
| (* --- 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