This commit is contained in:
theskywinds 2025-04-03 20:09:51 +02:00
commit bbe36fdfc5
6 changed files with 1076 additions and 0 deletions

BIN
Archive.tar.gz Normal file

Binary file not shown.

7
CMakeLists.txt Normal file
View File

@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.30)
project(AdventofCode2024)
set(CMAKE_CXX_STANDARD 20)
add_executable(AdventofCode2024
main.cpp)

1000
input.txt Normal file

File diff suppressed because it is too large Load Diff

1
inputexample.txt Normal file
View File

@ -0,0 +1 @@
34213 43539

35
main.cpp Normal file
View File

@ -0,0 +1,35 @@
#include <algorithm>
#include <fstream>
#include <iostream>
#include <vector>
int main() {
static std::fstream mainFile("/home/theskywinds/Programs/Owned programs/AdventofCode2024/input.txt");
if (!mainFile.is_open()) {
std::cerr << "Failed to open file\n";
return 1;
}
std::pair<std::vector<int>, std::vector<int>> listPair;
listPair.first.resize(1000);
listPair.second.resize(1000);
int64_t total{0};
int64_t tracker{0};
for (int i = 0; mainFile.good(); i++) {
mainFile >> listPair.first[i] >> listPair.second[i];
tracker++;
}
sort(listPair.first.begin(), listPair.first.end());
sort(listPair.second.begin(), listPair.second.end());
for (size_t i = 0; i < tracker ; i++) {
total += static_cast<int64_t>(std::abs(listPair.first[i] - listPair.second[i]));
}
std::cout << total << '\n';
}

33
solution.cpp Normal file
View File

@ -0,0 +1,33 @@
#include <day_01/common.hpp>
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
#include <cmath>
int main() {
std::vector<int> left, right;
long dist = 0;
try {
// day_01::parseInput("test-input.txt", left, right);
day_01::parseInput("input.txt", left, right);
}
catch (const std::exception& e) {
std::cerr << e.what();
return 1;
}
size_t numPairs = left.size();
std::cout << numPairs << '\n';
for (size_t i = 0; i < numPairs; i++) {
int templ = day_01::findAndEjectMin(left);
int tempr = day_01::findAndEjectMin(right);
dist += std::abs(templ - tempr);
// std::cout << "most min left:" << " " << templ << "; most min right:" << " " << tempr << '\n';
}
std::cout << dist << '\n';
return 0;
}