Welcome to MSDN Blogs Sign in | Join | Help

jaredpar's WebLog

Code, rants and ramblings of a programmer.
Euler and F#

I've been looking for some new problems to work on in F# to get more comfortable with the language.  I've been rather slack of late because of other projects but I had a little bit of time this week.  I decided it would be fun to join the crowd and play away at the problems on the project euler site.  That being said, answer #1.

module Euler =
    let problem1() =
        let test i = 
            match (0 = i % 3) || (0 = i % 5) with
                | true -> Some i
                | false -> None
        let targetSeq = Seq.choose test [0..999]
        Seq.sum targetSeq

Published Monday, September 08, 2008 8:00 AM by Jared Parsons

Filed under:

Comments

# funny wallpaper » Euler and F# @ Monday, September 08, 2008 8:15 AM

PingBack from http://housesfunnywallpaper.cn/?p=4551

funny wallpaper » Euler and F#

# a-foton » Euler and F# @ Monday, September 08, 2008 8:15 AM

PingBack from http://blog.a-foton.ru/2008/09/euler-and-f/

a-foton » Euler and F#

# re: Euler and F# @ Monday, September 08, 2008 9:02 AM

Here's my solution:

let p1_solution() =

 {0..999}

 |> Seq.filter (fun x -> x%3=0 || x%5=0)

 |> Seq.sum

IMHO Seq.filter is more logical than Seq.choose in this case.

brilsmurf

# re: Euler and F# @ Tuesday, September 09, 2008 1:14 AM

@brilsmurf,

Thanks for pointing me to that.  I spent roughly 30 minutes looking for this function but read right past the documentation and was stuck with choose.

Jared Parsons

New Comments to this post are disabled
Page view tracker