Skip to content

Instantly share code, notes, and snippets.

@testfirstcoder
Last active November 17, 2015 12:55
Show Gist options
  • Save testfirstcoder/009ed18004200c4330ed to your computer and use it in GitHub Desktop.
Save testfirstcoder/009ed18004200c4330ed to your computer and use it in GitHub Desktop.
ProjectEuler in F#
[|1..1000 - 1|] |> Array.filter (fun e -> e % 3 = 0 || e % 5 = 0) |> Array.sum
#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
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)
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
[for i in 1..1000 -> pown (bigint i) i] |> List.sum |> (fun e -> e % pown 10I 10)
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