Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Displayed No results found message #1015

Merged
merged 20 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Calculators/Time-Complexity-Calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# <p align="center">Time Complexity Calculator</p>

## Description :-

Calculator which provides the time complexity of given programs based on certain criteria such as no. of for loops, recursion, sorting etc.

## Tech Stacks :-

- HTML
- CSS
- JavaScript

## Screenshots :-

![image](https://github.com/Rakesh9100/CalcDiverse/assets/73993775/89c29e55-b71f-49a6-b46a-cb199e437f4b)
22 changes: 22 additions & 0 deletions Calculators/Time-Complexity-Calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!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">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">
<title>Time Complexity Calculator</title>
</head>
<body>
<div class="container">
<h1>Time Complexity Calculator</h1>
<form id="complexityForm">
<label for="algorithm">Algorithm:</label>
<textarea id="algorithm" name="algorithm" rows="10" cols="50" placeholder="Enter your algorithm here..."></textarea>
<button type="button" onclick="calculateComplexity()">Calculate Complexity</button>
</form>
<div id="result"></div>
</div>
<script src="script.js"></script>
</body>
</html>
39 changes: 39 additions & 0 deletions Calculators/Time-Complexity-Calculator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// script.js
function calculateComplexity() {
const algorithm = document.getElementById('algorithm').value;
const resultDiv = document.getElementById('result');

if (!algorithm) {
resultDiv.innerHTML = "Please enter an algorithm.";
return;
}

let complexity = "Unknown";

// Remove comments and whitespaces
const cleanedAlgorithm = algorithm.replace(/\/\/.*|\/\*[\s\S]*?\*\/|^\s*|\s*$/gm, '');

// Check for various patterns
const forLoopCount = (cleanedAlgorithm.match(/for\s*\(.*\)\s*{[^}]*}/g) || []).length;
const whileLoopCount = (cleanedAlgorithm.match(/while\s*\(.*\)\s*{[^}]*}/g) || []).length;
const functionNameMatch = cleanedAlgorithm.match(/function\s+(\w+)\s*\(/);
const functionName = functionNameMatch ? functionNameMatch[1] : null;
const recursionCount = functionName ? (cleanedAlgorithm.match(new RegExp(`\\b${functionName}\\(.*\\)`, 'g')) || []).length : 0;
const sortingAlgorithms = /(sort\s*\(|mergeSort|quickSort|heapSort|timSort)/g;

if (sortingAlgorithms.test(cleanedAlgorithm)) {
complexity = "O(n log n) - Sorting algorithm";
} else if (forLoopCount > 1 || whileLoopCount > 1 || (forLoopCount > 0 && whileLoopCount > 0)) {
complexity = `O(n^${forLoopCount + whileLoopCount}) - Multiple nested loops`;
} else if (forLoopCount === 1 || whileLoopCount === 1) {
complexity = "O(n) - Single loop";
} else if (recursionCount > 1) {
complexity = "O(2^n) - Recursion";
} else if (recursionCount === 1) {
complexity = "O(n) - Tail recursion";
} else if (cleanedAlgorithm.includes('Math.floor') || (cleanedAlgorithm.includes('left') && cleanedAlgorithm.includes('right'))) {
complexity = "O(log n) - Logarithmic time";
}

resultDiv.innerHTML = `Estimated Time Complexity: ${complexity}`;
}
81 changes: 81 additions & 0 deletions Calculators/Time-Complexity-Calculator/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
body {
font-family: 'Roboto', sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background: linear-gradient(135deg, #74ebd5 0%, #ACB6E5 100%);
color: #333;
}

.container {
background: #fff;
padding: 30px 40px;
border-radius: 10px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
max-width: 600px;
width: 100%;
text-align: center;
transition: transform 0.3s ease;
}

.container:hover {
transform: translateY(-5px);
}

h1 {
margin-bottom: 20px;
font-size: 24px;
color: #4A90E2;
border-bottom: 2px solid #4A90E2;
display: inline-block;
padding-bottom: 5px;
}

form {
margin-bottom: 20px;
}

label {
display: block;
margin-bottom: 10px;
font-size: 18px;
font-weight: bold;
}

textarea {
width: 100%;
padding: 15px;
margin-bottom: 20px;
border: 2px solid #ddd;
border-radius: 5px;
font-size: 16px;
transition: border-color 0.3s ease;
}

textarea:focus {
border-color: #4A90E2;
outline: none;
}

button {
padding: 15px 30px;
border: none;
background-color: #4A90E2;
color: #fff;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
transition: background-color 0.3s ease;
}

button:hover {
background-color: #357ABD;
}

#result {
font-size: 18px;
color: #333;
margin-top: 20px;
}
23 changes: 23 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2092,6 +2092,20 @@ <h3>Calculates Hours, Minutes, Seconds for any entered time.</h3>
</div>
</div>
</div>
<div class="box">
<div class="content">
<h2>Time Complexity Calculator</h2>
<h3>Calculates the time complexity of given programs by the user.</h3>
<div class="card-footer">
<a href="./Calculators/Time-Complexity-Calculator/index.html" target="_blank">
<button>Try Now</button>
</a>
<a href="https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/Time-Complexity-Calculator" title="Source Code" target="_blank">
<img src="./assets/images/github.png" alt="Source Code"></img>
</a>
</div>
</div>
</div>
<div class="box">
<div class="content">
<h2>Time Zone Calculator</h2>
Expand Down Expand Up @@ -2302,6 +2316,15 @@ <h3>Calculates the linear density of the yarn from unit system to another.</h3>
</div>
</div>
</div>

<br>
<br>
<br>
<br>
<br>
<div id="noResults" style="color: white; font-weight: bold; font-size: 18px;"><p>No results found</p></div>


</div>

<!-- Calculator Section Ends Here -->
Expand Down