Wednesday 7 November 2012

Project Euler Problem #1

I just found this cool new website which has a bunch of interesting math/computer programming related problems. Heres my go at the first problem using Processing. It was quite trivial to solve in the inefficient way I did but some of the problems ahead are pretty intense!

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."

Here is the code:



int total = 0;
for (int i = 0; i<1000 code="code" i="i">
  if (i%3 == 0 || i%5 == 0) {
    total += i;
  }
}
fill(0);
text(total,0,70);

No comments:

Post a Comment