-
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 Bell Number Calculator (#1981)
- Loading branch information
1 parent
89e57c7
commit 6a6e5a3
Showing
5 changed files
with
239 additions
and
1 deletion.
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">Bell Number Calculator</p> | ||
|
||
## 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) |
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,28 @@ | ||
<!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>Bell Number Calculator</title> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h1>Bell Numbers Calculator</h1> | ||
<p>Bell numbers count the number of ways to partition a set. This tool calculates the Bell number for a given value of n.</p> | ||
|
||
<div class="input-section"> | ||
<label for="numberInput">Enter a number (n):</label> | ||
<input type="number" id="numberInput" min="0" max="100" step="1"> | ||
<button onclick="calculateBellNumber()">Calculate Bell Number</button> | ||
</div> | ||
|
||
<div class="result-section"> | ||
<h2>Result:</h2> | ||
<p id="bellNumberResult">Please enter n to calculate nth Bell number.</p> | ||
</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,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]; | ||
} |
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,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; | ||
} | ||
} |
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