CODING CHALLENGE - LETS SEE HOW SMART Jow Forums IS

First Problem:


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

First correct response gets second problem etc, pls don't look up the answer. Correct code with lowest execution time wins.

Attached: Capture.png (472x591, 529K)

ill do your homework, but pay me first

fat plastic

Trivial.

Next question.

It's literally elementary school level of math

Attached: 1484850493852.jpg (824x579, 85K)

Do your own homework.

>it's trivial

>no one answers the question yet

I don't even wanna see the code, I know the answer too.

Last 3 digits are "168"

I just wanna check you guys aren't retarded

cute whore

i don't know how to type summations format else i'd post :/

234168

VERY CLOSE. But did you forget to take something away you added twice?

I don't think so.
I subtract the times 3 and 5 appear exactly once, or am I mentally fucking up?

sum=0;
for i=[3,5,-15]
n=floor(1000/abs(i));
sum=sum + (n*(n+1))/2*i
end

I think I know your problem, the question says below 1000 and you probably added 1000 (multiple of 5). The correct answer is 233168.

Anyway good job, here is the second question:

"Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms."

That's why people usually state whether the number is included in such tests.

[codesum=0;
for i=[3,5,-15]
n=floor(999/abs(i));
sum=sum + (n*(n+1))/2*i
end[/code]

Why don't you just direct people to project Euler where you are copying this shit from?

int main()
{
int sum = 0;
for (int i = 3; i < 1000; i++) {
if ((i % 3 == 0) || (i % 5 == 0)) sum += i;
}
printf("sum: %d", sum);
}

233168

We just did this you faggot. Except better.

(some->> 1000
(range 0)
(filter #(or (zero? (mod % 3))
(zero? (mod % 5))))
(reduce +))
=> 233168

Trash challenge, try doing better nigger

Hey boss, how about you toss the sauce first as incentive?

>using loops
Jesus fucking Christ.

int sum(int limit)
{
return (limit * limit + limit) / 2;
}

int multsum(int limit, int multiple)
{
return sum(limit / multiple) * multiple;
}

int main()
{
int i, tot = 0, lim = 1000;

printf("%d\n", multsum(lim - 1, 3) + multsum(lim - 1, 5) - multsum(lim - 1, 15));

return 0;
}

>all these pajeets using a loop

>hurr durr let's copy first Project Euler question and pretend like it's a mystery what the next question will be

Attached: 89822e889c089360cb14a8ce158cfe48.jpg (604x544, 38K)

best solution

for(int i = 0; i

Attached: kot_23.jpg (1200x851, 110K)

This is basically fizz buzz but with like 1 or 2 extra steps. Takes all the multiple of 3 and 5 and collect them then output the sum of that collection.

>10000

Attached: 00f10e94af370c3475401267c9a4aded.jpg (247x247, 10K)

I want to impregnate those tits

I want to cum her

4613732

since i'm learning js right now, i did it there

fib = [1, 2];
old = 1;
cur = 2;
while(cur

on second thought could have done away with the array by evaluating if it gets summed in the first loop

This is literally the first prompt on projecteuler.net

this is what I think.

that shit OP create challenge so someone can do his homework, clever joke.

To be nicer than these guys:

Note that, for instance, getting "the sum of all multiples of 3 up-to-and-including 300" is merely 3 times the sum of 1 to 100. This is because (1+2+3+....+100)*3 = 3+6+9...+300. So we can apply the same logic to the problem.

To get the sum of all multiples of 3 under 1000 (aka less than/equal to 999), you just do the sum of 1 to 333 and multiply by 3. To get the sum of all multiples of 5 under 1000 (again, less than/equal to 999), you do the sum of 1 to 199 and multiply by 5. Programming language division makes this even easier, since 999/5 will round down to 199. And then you subtract the repeats, using 15 as the base.

It requires a Gaussian sort of cleverness to see this the first time you encounter this problem, so you shouldn't feel bad for immediately thinking to use loops.

>It requires a Gaussian sort of cleverness
Being compared to Gauss is fun and all, but it's pretty fucking far from accurate.

"Child Gaussian" would be more accurate, but it's still apt. Unless you work with sums pretty often, there's no reason why you'd easily come up with the trick, especially as this is a programming challenge that seems like a perfect fit for using loops.

>Can't even code