Skip to content

Commit 656a70f

Browse files
committed
Add Project Euler
1 parent ebaf802 commit 656a70f

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Project Euler: Problem 1: Multiples of 3 and 5
3+
*
4+
* 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.
5+
*
6+
* Find the sum of all the multiples of 3 or 5 below the provided parameter value number.
7+
*/
8+
9+
function multiplesOf3and5(number) {
10+
let sum = 0;
11+
12+
for (let i = 3; i < number; i++) {
13+
if (i % 3 === 0 || i % 5 === 0) {
14+
sum += i;
15+
}
16+
}
17+
18+
return sum;
19+
}
20+
21+
console.log(multiplesOf3and5(1000)); //233168
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Project Euler: Problem 2: Even Fibonacci Numbers
3+
*
4+
* 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:
5+
*
6+
* 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
7+
*
8+
* By considering the terms in the Fibonacci sequence whose values do not exceed nth term, find the sum of the even-valued terms.
9+
*/
10+
11+
12+
function fiboEvenSum(n) {
13+
let first = 0,
14+
second = 1,
15+
sum = 0,
16+
num = 0;
17+
18+
for (let i = 0; i <= n; i++) {
19+
num = first + second;
20+
first = second;
21+
second = num;
22+
23+
if (num % 2 === 0) {
24+
sum += num;
25+
}
26+
}
27+
28+
return sum;
29+
}
30+
31+
fiboEvenSum(10);

0 commit comments

Comments
 (0)