Last active
December 19, 2024 20:12
-
-
Save mudassaralichouhan/178bfd172f6745a53b4543275645d11e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
bool isEven(int n) { | |
return (n & 1) == 0; | |
} |
This file contains hidden or 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
/* | |
* Sieve of Eratosthenes: An efficient algorithm to find all prime numbers up to a given limit. | |
* Time complexity: O(n log(log n)) | |
* Space complexity: O(n) | |
*/ | |
#include <iostream> | |
#include <vector> | |
#include <cstdlib> | |
std::vector<bool> sieveOfEratosthenes(int n) { | |
std::vector<bool> primes(n + 1, true); | |
primes[0] = primes[1] = false; | |
for (int i = 2; i * i <= n; i++) { | |
if (primes[i]) { | |
for (int j = i * i; j <= n; j += i) { | |
primes[j] = false; | |
} | |
} | |
} | |
return primes; | |
} | |
bool isPrime(int number) { | |
if (number <= 1) return false; | |
for (int i = 2; i * i <= number; i++) { | |
if (number % i == 0) return false; | |
} | |
return true; | |
} | |
int main() { | |
{ | |
int n = 100, i = 1, count = 0; | |
std::vector<bool> primes = sieveOfEratosthenes(n); | |
for (int i = 2; i <= primes.size(); i++) { | |
if (primes[i]) { | |
std::cout << i << ' '; | |
} | |
} | |
} | |
std::cout << std::endl; | |
{ | |
int n = 100, count = 0, number = 2; | |
while (count < n) { | |
if (isPrime(number)) { | |
std::cout << number << " "; | |
count++; | |
} | |
number++; | |
} | |
} | |
std::cout << std::endl; | |
return EXIT_SUCCESS; | |
} |
This file contains hidden or 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
void swap(int &a, int &b) { | |
a ^= b; | |
b ^= a; | |
a ^= b; | |
} |
function findMatchingWords(words, pattern) {
// Convert the pattern to a regular expression
// Replace '?' with '.' (matches any single character)
// Replace '_' with '.' (matches any single character)
const regexPattern = pattern.replace(/\?/g, '.').replace(/_/g, '.');
const regex = new RegExp(`^${regexPattern}$`); // Anchors the regex to match the whole word
// Filter the words that match the regex
return words.filter(word => regex.test(word));
}
// Example usage
const wordsList = ['cat', 'bat', 'hat', 'heat', 'helt', 'help', 'hell', 'he'll', 'heatwave'];
const pattern1 = '?at'; // Matches 'cat', 'bat', 'hat'
const pattern2 = 'he_l'; // Matches 'help', 'hell'
const matches1 = findMatchingWords(wordsList, pattern1);
const matches2 = findMatchingWords(wordsList, pattern2);
console.log(`Matches for '${pattern1}':`, matches1);
console.log(`Matches for '${pattern2}':`, matches2);
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sure! I'd be happy to provide detailed information on both the Blockchain Prototype and the Maze Solver Visualization projects. Below, I'll break down each project, explain how the data structures are utilized, and provide implementation details to help you get started.
1. Blockchain Prototype
Project Overview
Understanding the Components
a. Blockchain as a Linked List
b. Transaction Pool as a Stack
c. Merkle Trees for Transaction Verification
Implementation Details
1. Define the Block Structure
2. Implement the Linked List (Blockchain)
3. Transaction Pool Using Stack
4. Implement the Merkle Tree
5. Block Creation and Mining
Additional Considerations
previous_hash
matches thehash
of the previous block.Extensions
2. Maze Solver Visualization
Project Overview
Understanding the Components
a. Maze Representation
b. Pathfinding Algorithms
c. Visualization
Implementation Details
1. Maze Grid Creation
2. Implement DFS Algorithm Using a Stack
3. Implement BFS Algorithm Using a Queue
4. Neighbor Retrieval Function
5. Path Reconstruction
6. Visualization
matplotlib
,pygame
, ortkinter
can be used for visualization.Additional Considerations
Extensions
Next Steps
Choose a Programming Language:
tkinter
,pygame
) and cryptography (hashlib
).Set Up the Development Environment:
Plan the Project Structure:
Implement Incrementally:
Documentation and Testing:
Seek Feedback:
Additional Resources
Blockchain Resources:
Maze Solver Resources:
Feel free to ask if you need more specific code examples, explanations on certain parts, or guidance on how to proceed with any aspect of these projects. Good luck with your implementation!