Project Euler: Problem 1

To solve this problem I used a pretty straight forward LINQ statement. It basically just generates all the numbers from 0 to 999, filters out the numbers not dividable by 3 or 5, and then sums those up.

  var multiples = new long[] {3, 5};
  var answer =  Enumerable
    .Range(0, 1000)
    .Where(x => multiples.Any(y =>; x%y == 0))
    .Sum();

The answer to that would then be 233168, and it the code took less than 10 milliseconds to find.

So, how did you solve it? What do you think about my solution?

2 thoughts on “Project Euler: Problem 1

  1. the only proble is there should not be a semi colon in the Where

    var multiples = new long[] {3, 5};
    var answer = Enumerable
    .Range(0, 1000)
    .Where(x => multiples.Any(y =>; x%y == 0))
    .Sum();

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>