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();
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?
Pages: 1 2
I am just starting to look at this great website. I like your solution a lot. Nice one.
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();