Contents tagged with project euler

Project Euler in F# - Problems 4 - 6

Sep 04 2011No Comments by stanley

Problem 4 Find the largest palindrome that results from the multiplication of two numbers under 1000 I feel like I have a strange obsession with the Seq.unfold function. That function does most of the heavy lifting here. Although the wise Euler pointed out to me that I can avoid duplicate multiplication factors, and keep track of the largest palindrome so far to avoid unnecessary `isPalindrome` checks. [fsharp] let problem4 () = let isPalindrome (value: string) = match value. …

f#, project euler Read more

Project Euler in F# - Problems 1 - 3

Sep 02 2011No Comments by stanley

Problem 1 Find the sum of all the multiples of 3 or 5 below 1000. Brute force is the first thing that comes to mind [fsharp] let problem1 () = {1 .. 999} |> Seq.filter (fun x -> (x % 3 = 0) || (x % 5 = 0)) |> Seq.sum [/fsharp] But the wise Euler shows Math to be a better tactic, as his answer is unquestionably faster. [fsharp] let problem1_correct () = let target = 999 let sumDivisibleBy value = let p = target / value value * (p * (p + 1)) / 2 …

f#, project euler Read more

Project Euler in F#

Sep 02 2011No Comments by stanley

While job hunting this time around, a recruiter pointed me to a website called Project Euler, as a great place to practice. Project Euler is a series of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve. Although mathematics will help you arrive at elegant and efficient methods, the use of a computer and programming skills will be required to solve most problems. The problems always seem overly complicated, and somehow ask …

f#, project euler Read more