Skip to content

Commit

Permalink
day 25 part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
K20shores committed Dec 25, 2024
1 parent 46aa52f commit e857f3a
Showing 1 changed file with 9 additions and 45 deletions.
54 changes: 9 additions & 45 deletions 2024/src/day25.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,11 @@ struct Data {
std::vector<std::vector<int>> locks;
};

void sort_values(std::vector<std::vector<int>>& values, bool reverse = false) {
std::sort(values.begin(), values.end(), [&](const auto& a, const auto& b) {
for(int i = 0; i < a.size(); ++i) {
if (a[i] != b[i]) {
if (reverse) {
return a[i] > b[i];
}
return a[i] < b[i];
}
}
return false;
});
}

int part1(const Data &data)
{
auto keys = data.keys;
auto locks = data.locks;
sort_values(keys);
sort_values(locks);
for(auto& key : keys) {
std::cout << std::format("key: {} {} {} {} {}\n", key[0], key[1], key[2], key[3], key[4]);
}
std::cout << std::format("-----\n");
for(auto& lock : locks) {
std::cout << std::format("lock: {} {} {} {} {}\n", lock[0], lock[1], lock[2], lock[3], lock[4]);
}
std::cout << std::format("-----\n");
std::cout << std::format("Number of keys: {}\n", keys.size());
std::cout << std::format("Number of locks: {}\n", locks.size());

int sum = 0;
for(auto key: keys) {
for(auto lock: locks) {
for(auto key: data.keys) {
for(auto lock: data.locks) {
bool valid = true;
for(int i = 0; i < key.size(); ++i) {
if (key[i] + lock[i] > 5) {
Expand All @@ -53,15 +24,6 @@ int part1(const Data &data)
}
}
if (valid) {
// std::cout << "key: ";
// for(int i = 0; i < key.size(); ++i) {
// std::cout << std::format("{} ", key[i]);
// }
// std::cout << "lock: ";
// for(int i = 0; i < lock.size(); ++i) {
// std::cout << std::format("{} ", lock[i]);
// }
// std::cout << " fit\n";
sum++;
}
}
Expand All @@ -87,6 +49,7 @@ Data parse()
bool locks = true;
bool last_empty = true;
std::vector<int> count(5, 0);
int j = 0;
while (std::getline(file, line))
{
if (line.size() == 0) {
Expand All @@ -105,16 +68,17 @@ Data parse()
last_empty = false;
continue;
}
else if (line == "#####") {
last_empty = false;
continue;
}
if (line == "....." && last_empty) {
locks = false;
last_empty = false;
continue;
}
last_empty = false;
++j;
if (j == 6) {
j = 0;
continue;
}
for(int i = 0; i < line.size(); ++i) {
count[i] += line[i] == '#';
}
Expand Down Expand Up @@ -164,7 +128,7 @@ int main(int argc, char **argv)
{
Data data = parse();

int answer1 = 0;
int answer1 = 2885;
int answer2 = 0;

auto first = part1(data);
Expand Down

0 comments on commit e857f3a

Please sign in to comment.