-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4sem_88.cpp
67 lines (52 loc) · 1.96 KB
/
4sem_88.cpp
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <vector>
#include <chrono>
#include <fstream>
using namespace std;
using namespace std::chrono;
// Function to generate permutations of truth table and calculate time complexity
void generatePermutations(vector<vector<bool>>& permutations, int n, ofstream& csvFile) {
int numPermutations = 1 << n; // Number of permutations = 2^n
// Iterate over all possible combinations of truth values
for (int i = 0; i < numPermutations; ++i) {
vector<bool> currentPermutation(n);
// Start measuring time
auto start = high_resolution_clock::now();
// Generate the truth values for the current permutation
for (int j = 0; j < n; ++j) {
currentPermutation[j] = (i >> j) & 1; // Extract j-th bit of i
}
// Stop measuring time
auto stop = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(stop - start);
// Write time complexity to CSV file
csvFile << duration.count() << endl;
// Add the current permutation to the list of permutations
permutations.push_back(currentPermutation);
}
}
// Function to display permutations of truth table
void displayPermutations(const vector<vector<bool>>& permutations) {
for (const auto& permutation : permutations) {
for (bool value : permutation) {
cout << value << " ";
}
cout << endl;
}
}
int main() {
int n;
cout << "Enter the number of variables in the truth table: ";
cin >> n;
vector<vector<bool>> permutations;
ofstream csvFile("time_complexity.csv");
if (!csvFile.is_open()) {
cerr << "Error: Could not open the CSV file!" << endl;
return 1;
}
generatePermutations(permutations, n, csvFile);
cout << "Permutations of the truth table:" << endl;
displayPermutations(permutations);
csvFile.close();
return 0;
}