-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheatSheetMaker.cpp
More file actions
71 lines (60 loc) · 2.44 KB
/
CheatSheetMaker.cpp
File metadata and controls
71 lines (60 loc) · 2.44 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include <vector>
#include <cmath>
#include <fstream>
#include <json/json.h>
#include <chrono>
using namespace std;
void generateCombinations(vector<int>& currentCombination, int remainingArea, int remainingWidth, int smallestSquare, vector<vector<int>>& combinations) {
if (remainingArea == 0) {
combinations.push_back(currentCombination);
return;
}
else if (remainingArea < 0 || remainingWidth == 0) {
return;
}
for (int i = smallestSquare; i <= min(remainingWidth, static_cast<int>(sqrt(remainingArea))); i++) {
currentCombination.push_back(i);
generateCombinations(currentCombination, remainingArea - i * i, min(i, remainingArea - i * i), i, combinations);
currentCombination.pop_back();
}
}
void getSquareCombinations(int width, int smallestSquare, vector<vector<int>>& combinations) {
vector<int> currentCombination;
generateCombinations(currentCombination, width * width, width, smallestSquare, combinations);
}
int main() {
int smallest_square = 2; // Specify the smallest square to be considered
int max_width = 550;
auto start_time = std::chrono::high_resolution_clock::now();
Json::Value results;
for (int width = 1; width <= max_width; width++) {
vector<vector<int>> combinations;
getSquareCombinations(width, smallest_square, combinations);
Json::Value widthCombinations(Json::arrayValue);
for (const auto& combination : combinations) {
Json::Value jsonCombination(Json::arrayValue);
for (const auto& square : combination) {
jsonCombination.append(square);
}
widthCombinations.append(jsonCombination);
}
results[to_string(width)] = widthCombinations;
}
// Save the results to a JSON file
ofstream outputFile("/workspace/CheatSheet_test1.json");
if (outputFile.is_open()) {
outputFile << results;
outputFile.close();
cout << "Results saved to output.json" << endl;
auto end_time = std::chrono::high_resolution_clock::now();
// Calculate the elapsed time duration
std::chrono::duration<double> elapsed_seconds = end_time - start_time;
// Print the elapsed time in seconds
std::cout << "Elapsed time: " << elapsed_seconds.count() << " seconds" << std::endl;
}
else {
cout << "Failed to open output.json for writing" << endl;
}
return 0;
}