# Browse by Tags

Tagged Content List
• #### Blog Post: Project Euler Problem #14

Longest hailstone sequence with starting number under one-million. let hailstone n = Seq.unfold ( function 0L -> None | 1L -> Some(1L, 0L)                                     ...
• #### Blog Post: Project Euler Problem #13

First ten digits of sum of following one-hundred 50-digit numbers. It would be interesting to do without BigInts. Could use doubles with enough precision for just the first ten digits or some such thing, but just wanted the correct answer to plug into the site and I’m lazy :-) open System [37107287533902102798797998220837590246510135740250I;...
• #### Blog Post: Project Euler Problem #12

First triangle number to have over five hundred divisors. let naturals = Seq.unfold ( fun i -> Some(i, i + 1)) 1 // from prob7 let triangleNums = Seq.scan (+) 0 naturals let isFactor n d = n % d = 0 let factors n = seq { 1..int (sqrt (float n)) } |> Seq.filter (isFactor n) let numFactors n ...
• #### Blog Post: Project Euler Problem #11

Greatest product of four adjacent numbers (up, down, left, right, or diagonally) in this 20x20 grid: let grid = [|08;02;22;97;38;15;00;40;00;75;04;05;07;78;52;12;50;77;91;08; 49;49;99;40;17;81;18;57;60;87;17;40;98;43;69;48;04;56;62;00; 81;49;31;73;55;79;14;29;93;71;40;67;53;88;30;03;49;13;36;65; 52;70;95;23;04;60;11;42;69;24;68;56;01;32;56;71;37;02;36;91;...
• #### Blog Post: Project Euler Problem #10

Sum of primes below two-million. Easy problem, but way too slow (taking several minutes) with the naïve prime number generator from problem 7 . This new version is 10x faster, based on this paper: http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf (still not implementing the 'wheel' though; probably...
• #### Blog Post: Project Euler Problem #9

Pythagorean triplet where a + b + c = 1000 (2, 1) |> Seq.unfold ( fun (m, n) – >     Some([m * m - n * n; 2 * m * n; m * m + n * n],         if n + 1 < m then m, n + 1 else m + 1, 1)) |> Seq.find ( fun t -> List.sum t = 1000) |> List...
• #### Blog Post: Project Euler Problem #8

Largest products of five consecutive digits in this 1000-digit number. open System.Numerics let digits n = Seq.unfold ( fun i – > if i = 0I then None else Some(i % 10I, i / 10I)) n let consecutive = Seq.unfold ( function (a : BigInteger) :: (b :: c :: d :: e :: _ as t) – > Some(...
• #### Blog Post: Project Euler Problem #7

Find the 10001st prime let naturals = Seq.unfold ( fun i -> Some(i, i + 1 )) let primes = naturals 2 |> Seq.filter ( fun n -> seq { 2.. int (sqrt (float n)) } |> Seq.forall ( fun x -> n % x <> 0 )) Seq.nth 10000 primes
• #### Blog Post: Project Euler Problem #6

Difference between sum of the squares and the square of the sum of 1 - 100 : ( fun ns -> let sqr x = x * x (sqr (List.sum ns)) - (List.map sqr ns |> List.sum) ) [1..100]
• #### Blog Post: Project Euler Problem #5

Smallest number divisible by each of 1 to 20 : First cut (takes almost an hour to execute!): let isFactor n d = n % d = 0 {1..Int32.MaxValue} |> Seq.find ( fun n -> [1..20] |> List.forall (isFactor n)) Second cut (takes a millisecond!): let rec gcd a b = if b = 0 then...
• #### Blog Post: Project Euler Problem #4

Largest palindrome from product of two 3-digit numbers : let isPalendrome n = let s = n.ToString() |> List.of_seq s = List.rev s seq { for a in 100..999 do for b in a..999 -> a * b } |> Seq.filter isPalendrome |> Seq.max
• #### Blog Post: Project Euler Problem #3

Largest prime factor of 600851475143 : let primeFactors n = let isFactor n d = n % d = 0L let nextFactor n d = seq {d..n} |> Seq.find (isFactor n) (n, 2L, []) |> Seq.unfold ( fun (n, d, a) -> if isFactor n d then Some(d, ((n / d), d, (d :: a))) elif n > d then Some(d...
• #### Blog Post: Project Euler Problem #2

Sum of even terms in Fibonacci sequence which are < four-million : (1, 1) |> Seq.unfold ( fun (a, b) -> Some(a, (b, a + b))) // fibs |> Seq.takeWhile ( fun x -> x <= 4000000) |> Seq.filter ( fun x -> x % 2 = 0) |> Seq.sum I like how Fibonacci can be represented...
• #### Blog Post: Project Euler Problem #1

Project Euler is pretty darn cool. It’s a bunch of mathematical problems that require programming to solve. I’m having fun doing them in F#. They start very simple but quickly become more difficult. Problem 1 is to find the sum of all the multiples of 3 or 5 among the natural numbers below 1000: ...
Page 1 of 1 (14 items)