-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprep.js
More file actions
42 lines (40 loc) · 808 Bytes
/
prep.js
File metadata and controls
42 lines (40 loc) · 808 Bytes
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
// Project Euler 1 (PE1)
function multof5() {
var arr = [],
z = 0;
for (var i = 3; i < 1000; i++) {
// prevent repeated multiples of 3 and 5
if (i % 3 === 0 && i % 5 != 0) {
arr.push(i)
}
if (i % 5 === 0) {
arr.push(i)
}
}
// add all elements in array
for (var x = 0; x < arr.length; x++) {
z += arr[x];
}
console.log(z);
}
// PE2
function fibo() {
var z, x = 0,
y = 1,
a = 0,
arr = [];
for (var i = 0; i < 32; i++) {
z = x + y;
x = y;
y = z;
if (z % 2 === 0) {
arr.push(z);
}
}
//console.log(z);
// add em up:
for (var g = 0; g < arr.length; g++) {
a += arr[g];
}
console.log(a);
}