-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProblem1 - Multiples of 3 and 5.html
57 lines (53 loc) · 1.45 KB
/
Problem1 - Multiples of 3 and 5.html
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
55
56
57
<html>
<head>
<title>Project Euler, Problem 1: Multiples of 3 and 5</title>
<style>
#explanation {
visibility: hidden;
}
#problem {
text-align: center;
border: 2px solid black;
border-radius: 5px;
width: 85px;
cursor: default;
}
</style>
</head>
<body>
<p>
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.
</br></br>
Find the sum of all the multiples of 3 or 5 below 1000.
</p>
<div id="problem" onclick="projectEulerProblem1()">
Find Sum
</div>
<div id="explanation">
</br>
<div id="totalTime"></div>
<p>
To solve this, I used a for loop iterating from 3 to 1000.
</br></br>
If the number mod 3 or 5 was equal to 0 (divisible by either number) I added the value of that number to a "sum" variable.</br>
</p>
</div>
</body>
<script>
var sum = 0;
function projectEulerProblem1() {
var startTime = new Date();
for (e = 3; e < 1000; e++) {
if ((e % 3) === 0 || (e % 5) === 0) {
sum += e;
}
}
var endTime = new Date();
var totalTime = endTime - startTime;
document.getElementById("problem").innerHTML = sum;
document.getElementById("totalTime").innerHTML = totalTime + " ms";
document.getElementById("problem").style.cursor = "auto";
document.getElementById("explanation").style.visibility = "visible";
}
</script>
</html>