-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctions.cpp
More file actions
49 lines (40 loc) · 1.4 KB
/
Functions.cpp
File metadata and controls
49 lines (40 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <iomanip>
#include <thread>
#include <chrono>
#include <string>
#include <cmath>
using namespace std;
using namespace std::this_thread;
using namespace std::chrono;
bool isPrime(int n) {
if (n <= 1) return false; // 0, 1, and negative numbers are not prime
if (n <= 3) return true; // 2 and 3 are prime
// Eliminate even numbers and multiples of 3 quickly
if (n % 2 == 0 || n % 3 == 0) return false;
// Check divisors from 5 to sqrt(n), skipping even numbers
for (int i = 5; i <= sqrt(n); i += 6) {
if (n % i == 0 || n % (i + 2) == 0)
return false;
}
return true;
}
void showProgressBar(int progress, int total) {
const int barWidth = 50; // total width of the bar
float ratio = static_cast<float>(progress) / total;
int pos = static_cast<int>(barWidth * ratio);
std::cout << "\rProcessing [";
for (int i = 0; i < barWidth; ++i) {
if (i < pos) std::cout << "=";
else if (i == pos) std::cout << ">";
else std::cout << " ";
}
std::cout << "] " << std::setw(3) << static_cast<int>(ratio * 100) << "%";
std::cout.flush();
}
void typeEffect(const std::string &text, int delayMs = 50) {
for (char c : text) {
std::cout << c << std::flush; // Print character immediately
std::this_thread::sleep_for(std::chrono::milliseconds(delayMs)); // Delay
}
}