Skip to content

Commit

Permalink
problem3 and problem 4 added
Browse files Browse the repository at this point in the history
  • Loading branch information
goformarty committed Apr 20, 2017
1 parent de597fe commit 021902c
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 5 deletions.
31 changes: 28 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ <h5>What is Problem Eueler?</h5>
<p>Project Euler is a website with a series of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve. The motivation for starting Project Euler, and its continuation, is to provide a platform for the inquiring mind to delve into unfamiliar areas and learn new concepts in a fun and recreational context.</p>
<p>You can visit and join here: <a href="https://projecteuler.net/">https://projecteuler.net</a></p>
</div>
<!-- First Problem -->
<!-- Problem 1 -->
<div class="problemContainer">
<h2>Problem 1</h2>
<h4>Multiples of 3 and 5</h4>
<br />
<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. Find the sum of all the multiples of 3 or 5 below given number.</p>
<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 given number.</p>
<br />
<input id="input1" type="number" min="1" max="10000" placeholder="Enter your number" />
<button id="btn1">Calculate</button>
<br /><br />
<h5 class="answer">Answer: <span id="answer1"></span></h5>
</div>

<!-- Second Problem -->
<!-- Problem 2 -->
<div class="problemContainer">
<h2>Problem 2</h2>
<h4>Even Fibonacci numbers</h4>
Expand All @@ -41,7 +41,32 @@ <h4>Even Fibonacci numbers</h4>
<br /><br />
<h5 class="answer">Answer: <span id="answer2"></span></h5>
</div>

<!-- Problem 3 -->
<div class="problemContainer">
<h2>Problem 3</h2>
<h4>Largest prime factor</h4>
<br />
<p>The prime factors of 13195 are 5, 7, 13 and 29.<br /><br />What is the largest prime factor of the given number?</p>
<br />
<input id="input3" type="number" min="1" max="5000000" placeholder="Enter your number" />
<button id="btn3">Calculate</button>
<br /><br />
<h5 class="answer">Answer: <span id="answer3"></span></h5>
</div>

<!-- Problem 4 -->
<div class="problemContainer">
<h2>Problem 4</h2>
<h4>Largest palindrome product</h4>
<br />
<p>A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.<br /><br />Find the largest palindrome made from the product of two same digit long numbers - specify the number of digits.</p>
<br />
<input id="input4" type="number" min="1" max="10" placeholder="Enter your number" />
<button id="btn4">Calculate</button>
<br /><br />
<h5 class="answer">Answer: <span id="answer4"></span></h5>
</div>
</div>


Expand Down
65 changes: 63 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ function problem2() {
var y = 1;
var sum;
var total = 0;
var array = [];
if (max === "") {
return "Uoh-ooh, you forgot to specify a number!";
}
Expand All @@ -45,7 +44,6 @@ function problem2() {
for (sum=0; sum<max; sum=x+y) {
if (sum%2 === 0) {
total += sum;
array.push(sum);
}
x=y;
y=sum;
Expand All @@ -54,3 +52,66 @@ function problem2() {
}


// PROBLEM 3: DOM
var btn3 = document.getElementById("btn3");
btn3.onclick = function() {
document.getElementById("answer3").innerHTML = problem3();
};

// PROBLEM 3: FUNCTION
function problem3() {
var max = document.getElementById('input3').value;
if (max === "") {
return "Uoh-ooh, you forgot to specify a number!";
}
if(max > 5000000) {
return "Please specify a number between 0-5000000";
}
for (var i=2; i<=max; i++) {
if (!(max % i)) {
max /= i;
i--;
}
}
return i;
}

// PROBLEM 4: DOM
var btn4 = document.getElementById("btn4");
btn4.onclick = function() {
document.getElementById("answer4").innerHTML = problem4();
};

// PROBLEM 4: FUNCTION
function problem4() {
var max = document.getElementById('input4').value;

// function to get the number range
var a = function(max) {
var digits = [];
for (var i = 0; i<max; i++) {
digits.push(9);
}
return [Number(digits.join('')), Number(digits.slice(0, -1).join(''))];
};
var b = a;

var palindromeArray = [];
if (max === "") {
return "Uoh-ooh, you forgot to specify both numbers!";
}
if(max > 10) {
return "Please specify numbers between 0-10";
}
for (var x=a[0]; x>a[1]; x--) {
for (var y = b[0]; y>b[1]; y--) {
var multiply = x * y;
var stringMultiply = multiply.toString();
var reversedMultiply = reverseString(stringMultiply);
if (reversedMultiply === stringMultiply) {
palindromeArray.push(multiply);
}
}
}
return Math.max.apply(null, palindromeArray);
}
2 changes: 2 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ p {
text-align: center;
padding-top: 1.6em;
padding-bottom: 2em;
position: relative;
}

.title:after {
content: " ";
background-image: url(wavy-seperator.svg);
Expand Down

0 comments on commit 021902c

Please sign in to comment.