Welcome to MSDN Blogs Sign in | Join | Help

jaredpar's WebLog

Code, rants and ramblings of a programmer.

Syndication

News

Now Reading

Expert F#

What's a better book to read when learning F#?

Essential WPF

Thus far the best book I've read on WPF. Gets right down to working with WPF and the goals/history.

Purely Functional Data Structures

Reading this book makes me feel like I'm back in college. It will really get your mind going and is best read with a whiteboard handy.

Blog Roll

Eric Lippert
Dustin Campbell
Jon Skeet
Coding Horror
Brian McNamara
Brian Bondy
Hub FS
Full List

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