Created
June 10, 2011 08:10
-
-
Save nagat01/1018437 to your computer and use it in GitHub Desktop.
F#: Project Euler 1 to 11
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
| module ProjectEulerSolutions | |
| open System | |
| open System.Collections.Generic | |
| open System.IO | |
| open System.Linq | |
| open ProjectEulerLib | |
| let problem1 = [1..999] |> List.filter(fun x->x%3=0 || x%5=0) |> List.sum | |
| let problem2 = Seq.unfold(fun(a,b)->Some(a,(b,a+b))) (1,2) |> Seq.takeWhile((>=)4000000) |> Seq.filter(fun n->n%2=0) |> Seq.sum | |
| let problem3 = factorize 600851475143L |> List.rev |> List.head |> fst | |
| let problem4 = [ for i in 100..999 do for j in i..999 -> i*j ].Where(fun x -> x=reverseDigit x).Max() | |
| let problem5 = [1..20] |> Seq.collect factorize32 |> Seq.groupBy fst |> Seq.map(snd>>Seq.maxBy snd) |> Seq.fold(fun acc (p,n)->acc * pown p n)1 | |
| let problem6 =let ns = [1..100] in pown(List.sum ns)2 - (List.map(fun x->x*x) ns |> List.sum) | |
| let problem7 = primes() |> Seq.skip 10000 | |
| let problem8 = problem8str.Where(Char.IsDigit).Select(string>>Int32.Parse) |> Seq.windowed 5 |> Seq.map(Seq.reduce( * )) |> Seq.max | |
| let problem9 = [for a in 1..333 do for b in a..499 do let c=1000-a-b in if a*a+b*b=c*c then yield a*b*c] | |
| let problem10 = primes() |> Seq.takeWhile((>)2000000) |> Seq.fold(fun acc x->int64 x+acc)0L |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment