Geeks With Blogs
Buhay Programmer Dont byte more than you can chew February 2008 Entries
F# Solution (By Factorization) : Project Euler Problems 5
Problem: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest number that is evenly divisible by all of the numbers from 1 to 20? Solution: Finding the LCM can be done via factorization. Below is an excerpt from the wikipedia article. The unique factorization theorem says that every positive integer number greater than 1 can be written in only one way as a product of prime numbers. The prime numbers can be considered as the ......

Posted On Tuesday, February 19, 2008 1:15 AM

F# Solution : Project Euler Problems 4 & 6
These 2 problems have very short solutions so I'll put them together Problem 3: A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made from the product of two 3-digit numbers. Solution: let prodOf3digit = (100,100) |> Seq.unfold (fun (x,y) -> match y with | y when y < 0 -> None | y when x <= 999-> if (y <= 999) then Some(x*y, (x,y+1)) else if (x+1) <= 999 then Some ......

Posted On Monday, February 18, 2008 11:36 PM

F# Solution : Project Euler Problems 1-3
Problem 1 : If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. Solution : let mySeqP1 = [ 1 .. 999 ] |> Seq.filter (fun x -> ( (x % 5 = 0) || (x % 3 = 0)) ) |> Seq.fold(+) 0 printfn "sum = %i" mySeqP1 Problem 2: Find the sum of all the even-valued terms in the Fibonacci sequence which do not exceed one million. Solution : let sumofEven = (1,1) |> Seq.unfold ......

Posted On Monday, February 11, 2008 11:58 PM

Copyright © Erik Araojo | Powered by: GeeksWithBlogs.net