Testing testing one two 3

This commit is contained in:
ilikecats 2024-07-05 16:49:52 -07:00
commit b668ce7f8a
4 changed files with 35 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
# Ignore emacs backups
*~

3
Makefile Normal file
View File

@ -0,0 +1,3 @@
default:
mkdir bin
c++ main.cpp -o bin/primes

2
README.md Normal file
View File

@ -0,0 +1,2 @@
# test git repo
## teh code is to generate primes

28
main.cpp Normal file
View File

@ -0,0 +1,28 @@
// Generate primes using the sieve of eratosthenes
#include <iostream>
#include <vector>
int main() {
// TODO: make it work with GMP (https://gmplib.org/)
unsigned int nextnumber { 3 };
bool notprime;
std::vector<unsigned int> primes;
primes.push_back(2); // Initial prime
std::cout << "2\n";
while (true) {
notprime = false;
for (unsigned int i=0;i<primes.size();++i) {
if (nextnumber % primes[i] == 0) {
notprime = true;
break;
}
}
if (!notprime) {
primes.push_back(nextnumber);
std::cout << nextnumber << '\n';
}
nextnumber += 2; // Except for two, primes are odd. This skips even numbers.
}
}