-
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.
Added Partition Number Calculator (#1953)
- Loading branch information
1 parent
808c10a
commit 8c934d0
Showing
5 changed files
with
230 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# <p align="center">Partition Number Calculator</p> | ||
|
||
## Description :- | ||
|
||
Partition Number Calculator is a calculator that calculates the number of distinct partitions for a given non-negative integer. In mathematics, a partition of a number 𝑛 is a way of writing 𝑛 as a sum of positive integers, disregarding the order of the summands. | ||
|
||
## Tech Stacks :- | ||
|
||
- HTML | ||
- CSS | ||
- JavaScript | ||
|
||
## Screenshots:- | ||
|
||
![image](https://github.com/user-attachments/assets/a5cbf57b-0fa7-4600-949c-dc627b1d2c8a) |
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,29 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="stylesheet" href="style.css"> | ||
<title>Partition Number Calculator</title> | ||
</head> | ||
|
||
<body> | ||
<div class="container"> | ||
<h1>✨ Partition Number Calculator ✨</h1> | ||
<p class="description">Discover the number of ways to partition a given number!</p> | ||
<form id="partitionForm"> | ||
<div class="input-group"> | ||
<input type="number" id="numberInput" placeholder="Enter a number" min="0" aria-label="Enter a non-negative number" required> | ||
<span id="errorMessage" class="error-message"></span> | ||
</div> | ||
<button type="submit" id="calculateButton">🚀 Calculate</button> | ||
</form> | ||
<div id="result" class="result-box"></div> | ||
<div id="spinner" class="spinner hidden"></div> | ||
</div> | ||
|
||
<script src="script.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,48 @@ | ||
// DOM Elements | ||
const form = document.getElementById("partitionForm"); | ||
const numberInput = document.getElementById("numberInput"); | ||
const resultDiv = document.getElementById("result"); | ||
const errorMessage = document.getElementById("errorMessage"); | ||
const spinner = document.getElementById("spinner"); | ||
const calculateButton = document.getElementById("calculateButton"); | ||
|
||
// Partition Calculation Function | ||
function calculatePartition(num) { | ||
const partitions = Array(num + 1).fill(0); | ||
partitions[0] = 1; | ||
|
||
for (let i = 1; i <= num; i++) { | ||
for (let j = i; j <= num; j++) { | ||
partitions[j] += partitions[j - i]; | ||
} | ||
} | ||
return partitions[num]; | ||
} | ||
|
||
// Form Submission Event | ||
form.addEventListener("submit", (e) => { | ||
e.preventDefault(); | ||
|
||
const input = numberInput.value.trim(); | ||
const num = parseInt(input, 10); | ||
|
||
// Validation | ||
if (isNaN(num) || num < 0) { | ||
errorMessage.textContent = "⚠️ Please enter a valid non-negative number."; | ||
resultDiv.textContent = ""; | ||
return; | ||
} | ||
|
||
errorMessage.textContent = ""; | ||
resultDiv.textContent = ""; | ||
spinner.classList.remove("hidden"); | ||
calculateButton.disabled = true; | ||
|
||
// Simulate Computation | ||
setTimeout(() => { | ||
const result = calculatePartition(num); | ||
resultDiv.innerHTML = `🎉 Partition number for <strong>${num}</strong> is: <strong>${result}</strong>`; | ||
spinner.classList.add("hidden"); | ||
calculateButton.disabled = false; | ||
}, Math.min(500 + num * 5, 2000)); | ||
}); |
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,132 @@ | ||
body { | ||
font-family: "Poppins", Arial, sans-serif; | ||
margin: 0; | ||
padding: 0; | ||
background: linear-gradient(135deg, #a18cd1, #fbc2eb); | ||
background-size: cover; | ||
background-repeat: no-repeat; | ||
background-attachment: fixed; | ||
color: #333; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
min-height: 100vh; | ||
} | ||
|
||
/* Main Container */ | ||
.container { | ||
background: #ffffff; | ||
padding: 30px; | ||
border-radius: 15px; | ||
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2); | ||
text-align: center; | ||
max-width: 500px; | ||
width: 90%; | ||
position: relative; | ||
} | ||
|
||
h1 { | ||
color: #6c63ff; | ||
margin-bottom: 10px; | ||
font-size: clamp(1.5rem, 5vw, 1.8rem); | ||
} | ||
|
||
.description { | ||
font-size: 1rem; | ||
color: #555; | ||
margin-bottom: 20px; | ||
} | ||
|
||
/* Input Group */ | ||
.input-group { | ||
margin-bottom: 20px; | ||
} | ||
|
||
input { | ||
padding: 12px; | ||
font-size: 16px; | ||
width: 100%; | ||
border: 2px solid #ddd; | ||
border-radius: 8px; | ||
outline: none; | ||
transition: 0.3s ease; | ||
} | ||
|
||
input:focus { | ||
border-color: #6c63ff; | ||
box-shadow: 0 0 8px rgba(108, 99, 255, 0.3); | ||
} | ||
|
||
.error-message { | ||
display: block; | ||
margin-top: 5px; | ||
font-size: 0.85rem; | ||
color: #ff1744; | ||
min-height: 1rem; | ||
} | ||
|
||
/* Button */ | ||
button { | ||
padding: 12px 30px; | ||
font-size: 16px; | ||
color: #fff; | ||
background-color: #6c63ff; | ||
border: none; | ||
border-radius: 8px; | ||
cursor: pointer; | ||
transition: 0.3s ease; | ||
} | ||
|
||
button:disabled { | ||
background-color: #ccc; | ||
cursor: not-allowed; | ||
} | ||
|
||
button:hover:not(:disabled) { | ||
background-color: #5848e0; | ||
} | ||
|
||
/* Result Box */ | ||
.result-box { | ||
margin-top: 20px; | ||
padding: 15px; | ||
background: #f3f3f3; | ||
border-radius: 10px; | ||
font-size: 1.2rem; | ||
color: #444; | ||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); | ||
} | ||
|
||
/* Spinner */ | ||
.spinner { | ||
margin: 20px auto; | ||
border: 6px solid #f3f3f3; | ||
border-top: 6px solid #6c63ff; | ||
border-radius: 50%; | ||
width: 50px; | ||
height: 50px; | ||
animation: spin 1s linear infinite; | ||
} | ||
|
||
.spinner.hidden { | ||
display: none; | ||
} | ||
|
||
@keyframes spin { | ||
0% { | ||
transform: rotate(0deg); | ||
} | ||
|
||
100% { | ||
transform: rotate(360deg); | ||
} | ||
} | ||
|
||
/* Footer */ | ||
footer { | ||
margin-top: 20px; | ||
text-align: center; | ||
font-size: 0.9rem; | ||
color: #fff; | ||
} |
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