-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update with the project euler files (html, css, js)
- Loading branch information
Showing
6 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
# top-project-euler | ||
Project euler : problem 1 to 3 for The Odin Project | ||
http://www.theodinproject.com/web-development-101/javascript-basics | ||
|
||
Author : Andrea L. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
body { | ||
width: 75%; | ||
text-align : center; | ||
margin:auto; | ||
} | ||
|
||
h1 { | ||
color: #6b4e3d; | ||
} | ||
|
||
.content { | ||
border: solid 2px #6b4e3d; | ||
margin-bottom: 5px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<link rel="stylesheet" href="css/style.css" /> | ||
<title>The Odin Project : Project Euler</title> | ||
</head> | ||
|
||
<body> | ||
|
||
<h1>Problem Euler 1 : Multiples of 3 and 5</h1> | ||
<div class="content"> | ||
<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/> | ||
Find the sum of all the multiples of 3 or 5 below 1000. | ||
</p> | ||
<div> | ||
<input id="number_e1" type="text" placeholder="1000" > | ||
<button onclick="euler1()">Enter the number you want, then click!</button> | ||
<p>The sum of all the multiples of 3 or 5 below [<span id='max_e1'></span>] is : <span id="answer_e1"></span><br/> | ||
</p> | ||
</div> | ||
</div> | ||
|
||
<h1>Problem Euler 2 : Even Fibonacci numbers</h1> | ||
<div class="content"> | ||
<p> 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: <br/> | ||
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...<br/> | ||
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms. | ||
</p> | ||
<div> | ||
<input id="number_e2" type="text" placeholder="100000" > | ||
<button onclick="euler2()">Enter the number you want, then click!</button> | ||
<p>"The sum of the even-valued fibonacci numbers below [<span id='max_e2'></span>] is : <span id="answer_e2"></span><br/> | ||
</p> | ||
</div> | ||
</div> | ||
|
||
<h1>Problem Euler 3 : Largest prime factor</h1> | ||
<div class="content"> | ||
<p> The prime factors of 13195 are 5, 7, 13 and 29. | ||
<br/> | ||
What is the largest prime factor of the number 600851475143 ? | ||
</p> | ||
<div> | ||
<input id="number_e3" type="text" placeholder="13195" > | ||
<button onclick="euler3()">Enter the number you want, then click!</button> | ||
<p>The answer is : <span id="answer_e3"></span><br/> | ||
The prime factors are : <span id="factors_e3"></span></p> | ||
</div> | ||
</div> | ||
|
||
<script src="js/problem_e1.js"></script> | ||
<script src="js/problem_e2.js"></script> | ||
<script src="js/problem_e3.js"></script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
var euler1 = function () { | ||
var max = document.getElementById('number_e1').value ; | ||
var total = 0 ; | ||
var i = 1 ; | ||
var list = [] | ||
while (i < max) { | ||
if ((i % 3 === 0) || (i % 5 === 0)) { | ||
total += i ; | ||
list.push(i) ; | ||
i++ ; | ||
} else { | ||
i++ ; | ||
} | ||
} | ||
document.getElementById('max_e1').innerHTML = max ; | ||
document.getElementById('answer_e1').innerHTML = total ; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
var euler2 = function () { | ||
var max = document.getElementById('number_e2').value ; | ||
var fib1 = 1 ; | ||
var fib2 = 2 ; | ||
var fibN = 2 ; //for the first test | ||
var total = 0 ; | ||
var list = [] ; | ||
while (fibN < max) { | ||
if (fibN % 2 === 0) { | ||
total += fibN ; | ||
list += [fibN] ; | ||
} | ||
fibN = fib1 + fib2 ; | ||
fib1 = fib2 ; | ||
fib2 = fibN; | ||
|
||
} | ||
document.getElementById('max_e2').innerHTML = max ; | ||
document.getElementById('answer_e2').innerHTML = total ; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
var euler3 = function () { | ||
var number = document.getElementById('number_e3').value; | ||
var prime = 2 ; | ||
var prime_numbers = [] ; | ||
var prime_factors = [] ; | ||
var i = 2; | ||
var test = false ; | ||
while (prime < number) { | ||
while (i < prime) { | ||
if (prime % i === 0) { | ||
i++ ; | ||
test = true ; | ||
break; | ||
} else { | ||
i++; | ||
} | ||
} | ||
if (!test) { | ||
prime_numbers.push(prime) ; | ||
if (number % prime === 0) { | ||
prime_factors.push(prime) ; | ||
} | ||
} else { | ||
test = false ; | ||
} | ||
prime ++ ; | ||
i = 2 ; | ||
} | ||
document.getElementById('answer_e3').innerHTML = prime_factors[prime_factors.length -1] ; | ||
document.getElementById('factors_e3').innerHTML = prime_factors ; | ||
} |