diff --git a/Calculators/Partition-Number-Calculator/README.md b/Calculators/Partition-Number-Calculator/README.md new file mode 100644 index 000000000..fc7907409 --- /dev/null +++ b/Calculators/Partition-Number-Calculator/README.md @@ -0,0 +1,15 @@ +#

Partition Number Calculator

+ +## 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) diff --git a/Calculators/Partition-Number-Calculator/index.html b/Calculators/Partition-Number-Calculator/index.html new file mode 100644 index 000000000..7656e36b1 --- /dev/null +++ b/Calculators/Partition-Number-Calculator/index.html @@ -0,0 +1,29 @@ + + + + + + + + Partition Number Calculator + + + +
+

✨ Partition Number Calculator ✨

+

Discover the number of ways to partition a given number!

+
+
+ + +
+ +
+
+ +
+ + + + + \ No newline at end of file diff --git a/Calculators/Partition-Number-Calculator/script.js b/Calculators/Partition-Number-Calculator/script.js new file mode 100644 index 000000000..279efb3c6 --- /dev/null +++ b/Calculators/Partition-Number-Calculator/script.js @@ -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 ${num} is: ${result}`; + spinner.classList.add("hidden"); + calculateButton.disabled = false; + }, Math.min(500 + num * 5, 2000)); +}); \ No newline at end of file diff --git a/Calculators/Partition-Number-Calculator/style.css b/Calculators/Partition-Number-Calculator/style.css new file mode 100644 index 000000000..8cbc9012d --- /dev/null +++ b/Calculators/Partition-Number-Calculator/style.css @@ -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; +} \ No newline at end of file diff --git a/calculators.json b/calculators.json index 73ba33151..3ebfb0762 100644 --- a/calculators.json +++ b/calculators.json @@ -1739,6 +1739,12 @@ "link": "./Calculators/Partial-Derivative-Calculator/index.html", "source": "https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/Partial-Derivative-Calculator" }, + { + "title": "Partition Number Calculator", + "description": "Calculates the number of distinct partitions for a given non-negative integer.", + "link": "./Calculators/Partition-Number-Calculator/index.html", + "source": "https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/Partition-Number-Calculator" + }, { "title": "Password Strength Calculator", "description": "Calculates the strength of the Password.",