Last active
November 17, 2015 12:55
-
-
Save testfirstcoder/009ed18004200c4330ed to your computer and use it in GitHub Desktop.
ProjectEuler in F#
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
[|1..1000 - 1|] |> Array.filter (fun e -> e % 3 = 0 || e % 5 = 0) |> Array.sum |
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
#nowarn "40" | |
let rec fibonacci = seq { yield 1; yield! Seq.scan (+) 2 fibonacci } | |
fibonacci |> Seq.takeWhile (fun e -> e <= 4000000) |> Seq.filter (fun e -> e % 2 = 0) |> Seq.sum |
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
let numbers = [|1..10000|] | |
let properDivisorsSum = numbers |> Array.map(fun e1 -> e1, numbers.[0..e1/2] | |
|> Array.filter(fun e2 -> e1 % e2 = 0) | |
|> Array.sum) | |
properDivisorsSum | |
|> Array.filter(fun (a,b) -> properDivisorsSum | |
|> Array.exists(fun (c,d) -> a <> b && a = d && b = c)) | |
|> Array.sumBy(fun (a, _) -> a) |
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
Seq.unfold(fun (i, a, b) -> Some((i, a), (i + 1, b, a + b))) (1, 1I,1I) | |
|> Seq.find(fun (_, e) -> (e |> string |> String.length) = 1000) | |
|> fst |
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
[for i in 1..1000 -> pown (bigint i) i] |> List.sum |> (fun e -> e % pown 10I 10) |
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
let square x = x * x; | |
let range = [|1..100|]; | |
(range |> Array.sum |> square) - (range |> Array.map square |> Array.sum) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment