-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
54 lines (47 loc) · 1.01 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
console.log('test')
/**
* https://projecteuler.net/problem=1
*/
// Find the sum of all the multiples of 3 or 5 below 1000.
function problem1() {
let multipleSum = 0;
let i = 3;
let j = 5;
while (i < 1000 || j < 1000) {
if (i < 1000) {
multipleSum += i % 5 !== 0 ? i : 0;
i += 3;
}
if (j < 1000) {
multipleSum += j;
j += 5;
}
}
return multipleSum;
}
/**
* https://projecteuler.net/problem=2
*
* By considering the terms in the Fibonacci sequence whose values do not exceed four million,
* find the sum of the even-valued terms.
*
*/
function problem2() {
let sum = 0;
let n = 1;
let fib = 1;
let aux = 0;
while(n < 4000000) {
aux = fib;
fib += n;
n = aux;
if(fib % 2 === 0) sum += fib;
console.log(fib);
}
return sum;
}
function fibonacci(n) {
if(n <= 1) return 1;
return fibonacci(n - 1) + fibonacci(n - 2)
}
console.log(problem2());