I am an idiot
This commit is contained in:
parent
97cb3b6639
commit
f830923804
29
day6/day.cpp
29
day6/day.cpp
@ -3,35 +3,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
// this is defenitely my code
|
|
||||||
void heapPermutation(std::vector<char> &a, int size,
|
|
||||||
std::vector<std::vector<char>> &results) {
|
|
||||||
if (size == 1) {
|
|
||||||
results.push_back(a); // Store the current permutation
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < size; i++) {
|
|
||||||
heapPermutation(a, size - 1, results); // Recur with reduced size
|
|
||||||
|
|
||||||
// If size is odd, swap the first element with the last element
|
|
||||||
if (size % 2 == 1) {
|
|
||||||
std::swap(a[0], a[size - 1]);
|
|
||||||
} else { // If size is even, swap the current element with the last element
|
|
||||||
std::swap(a[i], a[size - 1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<std::vector<char>>
|
|
||||||
generatePermutations(const std::vector<char> &input) {
|
|
||||||
std::vector<char> chars = input; // Create a mutable copy of input
|
|
||||||
std::vector<std::vector<char>> results; // To store all permutations
|
|
||||||
heapPermutation(chars, chars.size(), results); // Generate permutations
|
|
||||||
return results; // Return all permutations
|
|
||||||
}
|
|
||||||
// end of defenitely my code
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
std::ifstream inputfile("input");
|
std::ifstream inputfile("input");
|
||||||
std::string input;
|
std::string input;
|
||||||
|
|||||||
0
day8/day.cpp
Normal file
0
day8/day.cpp
Normal file
Loading…
x
Reference in New Issue
Block a user