From 6a6e5a30e2e838df06af1fbf7201d43fdd3e6a52 Mon Sep 17 00:00:00 2001 From: Satyam Chakravorty Date: Fri, 10 Jan 2025 20:43:10 +0530 Subject: [PATCH] Added Bell Number Calculator (#1981) --- Calculators/Bell-Number-Calculator/README.md | 15 ++ Calculators/Bell-Number-Calculator/index.html | 28 ++++ Calculators/Bell-Number-Calculator/script.js | 36 +++++ Calculators/Bell-Number-Calculator/style.css | 153 ++++++++++++++++++ calculators.json | 8 +- 5 files changed, 239 insertions(+), 1 deletion(-) create mode 100644 Calculators/Bell-Number-Calculator/README.md create mode 100644 Calculators/Bell-Number-Calculator/index.html create mode 100644 Calculators/Bell-Number-Calculator/script.js create mode 100644 Calculators/Bell-Number-Calculator/style.css diff --git a/Calculators/Bell-Number-Calculator/README.md b/Calculators/Bell-Number-Calculator/README.md new file mode 100644 index 000000000..f9d1bc734 --- /dev/null +++ b/Calculators/Bell-Number-Calculator/README.md @@ -0,0 +1,15 @@ +#

Bell Number Calculator

+ +## Description :- + +This calculator allows users to calculate the value of nth Bell Number. + +## Tech Stacks :- + +- HTML +- CSS +- JavaScript + +## Screenshots :- + +![image](https://github.com/user-attachments/assets/da99b84b-2ad8-4377-b105-116c84ffbc4e) diff --git a/Calculators/Bell-Number-Calculator/index.html b/Calculators/Bell-Number-Calculator/index.html new file mode 100644 index 000000000..3bccaebcf --- /dev/null +++ b/Calculators/Bell-Number-Calculator/index.html @@ -0,0 +1,28 @@ + + + + + + + Bell Number Calculator + + +
+

Bell Numbers Calculator

+

Bell numbers count the number of ways to partition a set. This tool calculates the Bell number for a given value of n.

+ +
+ + + +
+ +
+

Result:

+

Please enter n to calculate nth Bell number.

+
+
+ + + + \ No newline at end of file diff --git a/Calculators/Bell-Number-Calculator/script.js b/Calculators/Bell-Number-Calculator/script.js new file mode 100644 index 000000000..f27bafc5d --- /dev/null +++ b/Calculators/Bell-Number-Calculator/script.js @@ -0,0 +1,36 @@ +function calculateBellNumber() { + const n = parseInt(document.getElementById("numberInput").value); + if (isNaN(n) || n < 0 || n >= 200) { + alert("Please enter a valid whole number less than 200."); + return; + } + + const bell = bellNumber(n); + document.getElementById("bellNumberResult").textContent = `nth Bell number for n = ${n} is ${bell}`; +} + +function bellNumber(n) { + // Base case + if (n === 0) return 1; + + // Create a 2D array to store values of Bell numbers + const bellTable = Array.from({ + length: n + 1 + }, () => Array(n + 1).fill(0)); + + // Initialize the first Bell number + bellTable[0][0] = 1; + + // Fill the table using dynamic programming + for (let i = 1; i <= n; i++) { + // Explicitly put the previous Bell number in the first column + bellTable[i][0] = bellTable[i - 1][i - 1]; + + // Fill the rest of the table + for (let j = 1; j <= i; j++) { + bellTable[i][j] = bellTable[i - 1][j - 1] + bellTable[i][j - 1]; + } + } + + return bellTable[n][0]; +} \ No newline at end of file diff --git a/Calculators/Bell-Number-Calculator/style.css b/Calculators/Bell-Number-Calculator/style.css new file mode 100644 index 000000000..492791de5 --- /dev/null +++ b/Calculators/Bell-Number-Calculator/style.css @@ -0,0 +1,153 @@ +* { + margin: 0; + padding: 0; + box-sizing: border-box; +} + +body { + font-family: 'Poppins', sans-serif; + background: linear-gradient(to right, #8E2DE2, #4A00E0); + display: flex; + justify-content: center; + align-items: center; + height: 100vh; + color: #fff; + padding: 0; + overflow: hidden; +} + +/* Container */ +.container { + background: rgba(255, 255, 255, 0.1); + backdrop-filter: blur(15px); + padding: 40px; + border-radius: 20px; + box-shadow: 0 15px 30px rgba(0, 0, 0, 0.3); + width: 100%; + max-width: 400px; + text-align: center; + border: 1px solid rgba(255, 255, 255, 0.2); + transition: all 0.3s ease-in-out; +} + +/* Title Styling */ +h1 { + font-size: 2.4em; + color: #fff; + font-weight: 600; + margin-bottom: 20px; + letter-spacing: 2px; +} + +/* Paragraph Text */ +p { + font-size: 1.1em; + color: #ddd; + margin-bottom: 20px; + font-weight: 300; +} + +/* Input Section */ +.input-section { + margin-bottom: 25px; +} + +.input-label { + font-size: 1.1em; + font-weight: 500; + margin-bottom: 10px; + display: block; +} + +input[type="number"] { + padding: 15px; + font-size: 1.1em; + border: none; + border-radius: 10px; + width: 100%; + margin-top: 10px; + background: #ffffff; + color: #333; + box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1); + transition: all 0.3s ease; + outline: none; +} + +input[type="number"]:focus { + box-shadow: 0 0 20px rgba(0, 0, 255, 0.3); + transform: translateY(-5px); +} + +button { + padding: 12px 20px; + background-color: #ff6f61; + color: white; + font-size: 1.1em; + border: none; + border-radius: 10px; + cursor: pointer; + margin-top: 20px; + box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2); + transition: all 0.3s ease; + font-weight: 600; +} + +button:hover { + background-color: #ff5733; + transform: translateY(-3px); + box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2); +} + +/* Result Section */ +.result-section { + margin-top: 20px; +} + +.result-heading { + font-size: 1.3em; + font-weight: 600; + color: #fff; +} + +#bellNumberResult { + font-size: 1.3em; + font-weight: 400; + color: #fff; + background-color: rgba(255, 255, 255, 0.2); + padding: 15px; + border-radius: 10px; + margin-top: 10px; + box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2); +} + +/* Hover effects and transitions */ +.container:hover { + transform: translateY(-10px); + box-shadow: 0 25px 40px rgba(0, 0, 0, 0.3); + transition: all 0.3s ease; +} + +button:active { + transform: translateY(2px); +} + +@media (max-width: 600px) { + .container { + padding: 30px; + max-width: 90%; + } + + h1 { + font-size: 2em; + } + + .input-section { + margin-bottom: 20px; + } + + button { + width: 100%; + font-size: 1em; + padding: 12px 0; + } +} \ No newline at end of file diff --git a/calculators.json b/calculators.json index 8808b32e6..5a213d10a 100644 --- a/calculators.json +++ b/calculators.json @@ -239,6 +239,12 @@ "link": "./Calculators/Beer-Lambert-Law-Calculator/index.html", "source": "https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/Beer-Lambert-Law-Calculator" }, + { + "title": "Bell Number Calculator", + "description": "Calculates the value of nth Bell Number.", + "link": "./Calculators/Bell-Number-Calculator/index.html", + "source": "https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/Bell-Number-Calculator" + }, { "title": "Beta Function Calculator", "description": "Calculate the ß value of two numbers in a single click!", @@ -2615,4 +2621,4 @@ "link": "./Calculators/Zodiac-Sign-Calculator/index.html", "source": "https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/Zodiac-Sign-Calculator" } -] \ No newline at end of file +]