F# Project Euler Problem 1


Recently I have started getting more exposure about F# at work. Another developer and myself managed woto build a scheduling service purely written in F#, and it was a very humbling experience.

I’ve gotten much more confidence now writing in F#, and starting to actually enjoy it more than C#. It’s a very different mindset and paradigm to write functionally.

We’ve also started a small community at work learning, sharing and practicing in F#. One of the interesting exercises is solving mathematical problems in F# from Project Euler.

Here’s my solution in solving 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.

let answer = seq {1..999}
|> Seq.filter (fun n -> n % 3 = 0 || n % 5 = 0)
|> Seq.sum

Simple enough 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: