-
Notifications
You must be signed in to change notification settings - Fork 406
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3943d00
commit aa2d1ae
Showing
8 changed files
with
179 additions
and
116 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
Binary file added
BIN
+726 KB
Calculators/Armstrong-Number-Calculator/Screenshot 2024-12-19 223205.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+637 KB
Calculators/Armstrong-Number-Calculator/Screenshot 2024-12-19 223247-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+637 KB
Calculators/Armstrong-Number-Calculator/Screenshot 2024-12-19 223247.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+639 KB
Calculators/Armstrong-Number-Calculator/Screenshot 2024-12-19 223326.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,50 +1,59 @@ | ||
// Function to find Armstrong numbers based on user input | ||
function findArmstrongNumbers() { | ||
const numOfDigits = document.forms.myform.numOfDigits.value; | ||
// Show the selected section and hide others | ||
function showSection(sectionId) { | ||
const sections = document.querySelectorAll('.card'); | ||
sections.forEach((section) => { | ||
if (section.id === sectionId) { | ||
section.classList.remove('hidden'); | ||
} else { | ||
section.classList.add('hidden'); | ||
} | ||
}); | ||
} | ||
|
||
// Validate user input | ||
if (numOfDigits === "" || Number.isNaN(numOfDigits) || numOfDigits < 1 || numOfDigits > 7) { | ||
alert("Please enter a valid number between 1 and 7"); | ||
} else { | ||
const n = parseInt(numOfDigits); | ||
const myElement = document.getElementById("armstrongNumbers"); | ||
const chunkSize = 1000; | ||
// Check if a number is Armstrong | ||
function checkArmstrong() { | ||
const numberInput = document.getElementById("number").value; | ||
const resultDiv = document.getElementById("result"); | ||
|
||
let startRange = Math.pow(10, n - 1); | ||
let endRange = Math.pow(10, n); | ||
if (!numberInput || isNaN(numberInput)) { | ||
resultDiv.innerHTML = "<span style='color: red;'>Please enter a valid number.</span>"; | ||
return; | ||
} | ||
|
||
let armstrongNumbers = []; | ||
const number = parseInt(numberInput, 10); | ||
const digits = numberInput.split("").map(Number); | ||
const power = digits.length; | ||
const sum = digits.reduce((acc, digit) => acc + Math.pow(digit, power), 0); | ||
|
||
// Process the range in smaller chunks to improve responsiveness | ||
for (let chunkStart = startRange; chunkStart <= endRange; chunkStart += chunkSize) { | ||
let chunkEnd = Math.min(chunkStart + chunkSize, endRange); | ||
if (sum === number) { | ||
resultDiv.innerHTML = `<span style="color: green;">Yes! ${number} is an Armstrong number.</span>`; | ||
} else { | ||
resultDiv.innerHTML = `<span style="color: red;">No, ${number} is not an Armstrong number.</span>`; | ||
} | ||
} | ||
|
||
// Check for Armstrong numbers in the current chunk | ||
for (let num = chunkStart; num < chunkEnd; num++) { | ||
if (isArmstrongOptimized(num, n)) { | ||
armstrongNumbers.push(num); | ||
} | ||
} | ||
} | ||
// Find Armstrong numbers | ||
function findArmstrongNumbers() { | ||
const numOfDigits = document.getElementById("numOfDigits").value; | ||
const resultDiv = document.getElementById("armstrongNumbers"); | ||
|
||
myElement.textContent = "Armstrong Numbers: " + armstrongNumbers.join(", "); | ||
if (!numOfDigits || isNaN(numOfDigits) || numOfDigits < 1 || numOfDigits > 7) { | ||
resultDiv.innerHTML = "<span style='color: red;'>Please enter a valid number between 1 and 7.</span>"; | ||
return; | ||
} | ||
} | ||
|
||
// Function to check if a number is an Armstrong number | ||
function isArmstrongOptimized(num, power) { | ||
let temp = num; | ||
let sumOfPowers = 0; | ||
const n = parseInt(numOfDigits, 10); | ||
const start = Math.pow(10, n - 1); | ||
const end = Math.pow(10, n); | ||
const armstrongNumbers = []; | ||
|
||
// Compute the sum of digits raised to the power | ||
while (temp > 0) { | ||
let digit = temp % 10; | ||
sumOfPowers += Math.pow(digit, power); | ||
temp = Math.floor(temp / 10); | ||
for (let i = start; i < end; i++) { | ||
const digits = i.toString().split("").map(Number); | ||
const sum = digits.reduce((acc, digit) => acc + Math.pow(digit, n), 0); | ||
if (sum === i) { | ||
armstrongNumbers.push(i); | ||
} | ||
} | ||
const additionalContent = document.getElementById('additionalContent'); | ||
additionalContent.innerText = 'Explanation: A number that is equal to the sum of cubes of its digits.'; | ||
|
||
// Check whether sum of powers equals the original number or not | ||
return sumOfPowers === num; | ||
|
||
resultDiv.innerHTML = `<span>Armstrong Numbers: ${armstrongNumbers.join(", ")}</span>`; | ||
} |
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,82 +1,104 @@ | ||
/* General Styling */ | ||
body { | ||
background-color: rgb(6, 0, 67); | ||
margin: 0; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
height: 100vh; | ||
margin: 0; | ||
padding: 0; | ||
font-family: 'Roboto', sans-serif; | ||
background: linear-gradient(135deg, #5f72bd, #9b23ea); | ||
color: #fff; | ||
} | ||
|
||
h1 { | ||
color: #c7c3c3; | ||
margin-bottom: 40px; | ||
.hidden { | ||
display: none; | ||
} | ||
|
||
.container { | ||
display: flex; | ||
flex-direction: column; | ||
color: rgb(5, 12, 43); | ||
font-size: large; | ||
align-items: center; | ||
justify-content: center; | ||
background-color: white; | ||
border-radius: 30px; | ||
padding: 100px; | ||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); | ||
/* Navbar */ | ||
.navbar { | ||
background: #4e45d5; | ||
padding: 10px 20px; | ||
position: sticky; | ||
top: 0; | ||
z-index: 1000; | ||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); | ||
} | ||
|
||
form { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
margin-bottom: 20px; | ||
.nav-container { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
max-width: 1200px; | ||
margin: 0 auto; | ||
} | ||
|
||
label { | ||
margin-bottom: 20px; | ||
.logo { | ||
color: #fff; | ||
font-size: 24px; | ||
font-weight: bold; | ||
text-decoration: none; | ||
} | ||
|
||
input { | ||
padding: 8px; | ||
margin-bottom: 20px; | ||
width: 150px; | ||
.nav-links { | ||
list-style: none; | ||
display: flex; | ||
gap: 20px; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
button { | ||
padding: 10px; | ||
background-color: #4e45d5; | ||
color: white; | ||
width: fit-content; | ||
box-shadow: 5px 5px 7px 0px #0000003f; | ||
font-size: 18px; | ||
cursor: pointer; | ||
transition: all 0.5s; | ||
font-weight: 500; | ||
border: solid 3px transparent; | ||
position: relative; | ||
z-index: 1; | ||
.nav-links li { | ||
display: inline; | ||
} | ||
|
||
.nav-links a { | ||
color: #fff; | ||
text-decoration: none; | ||
font-size: 16px; | ||
padding: 5px 10px; | ||
transition: background 0.3s, color 0.3s; | ||
} | ||
|
||
.nav-links a:hover { | ||
background: #3b34a6; | ||
border-radius: 5px; | ||
color: #fff; | ||
} | ||
|
||
button::before { | ||
content:""; | ||
position: absolute; | ||
background-color: #fff; | ||
top: 0px; | ||
left: 0; | ||
right: 0; | ||
bottom: 0px; | ||
z-index: -1; | ||
transform: scaleX(0); | ||
transform-origin: left; | ||
transition: all 0.8s; | ||
/* Container */ | ||
.container { | ||
width: 100%; | ||
max-width: 700px; | ||
margin: 50px auto; | ||
} | ||
|
||
/* Card Styling */ | ||
.card { | ||
background: #ffffff; | ||
color: #333; | ||
border-radius: 15px; | ||
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2); | ||
padding: 30px; | ||
text-align: center; | ||
} | ||
|
||
button:hover::before { | ||
transform: scaleX(1); | ||
/* Button */ | ||
button { | ||
padding: 10px 20px; | ||
background-color: #4e45d5; | ||
color: white; | ||
border: none; | ||
border-radius: 5px; | ||
cursor: pointer; | ||
} | ||
|
||
button:hover { | ||
border: solid 3px #4e45d5; | ||
color: black; | ||
background-color: #3b34a6; | ||
} | ||
|
||
/* Input Fields */ | ||
input { | ||
padding: 10px; | ||
width: 100%; | ||
max-width: 300px; | ||
margin-bottom: 15px; | ||
border: 1px solid #ccc; | ||
border-radius: 5px; | ||
} |