Skip to content

Instantly share code, notes, and snippets.

@maudzekod4000
Created December 13, 2024 19:27
Show Gist options
  • Save maudzekod4000/9c209f015ffbad1037c79c9efc7486d9 to your computer and use it in GitHub Desktop.
Save maudzekod4000/9c209f015ffbad1037c79c9efc7486d9 to your computer and use it in GitHub Desktop.
AOC-2024-Problem 3 Part 1
#include <iostream>
#include <fstream>
#include <string>
#include <ctype.h>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <sstream>
#include <regex>
using namespace std;
int main()
{
ifstream infile("input.txt");
if (!infile.is_open()) {
cout << "File prob\n";
return -1;
}
long long total = 0;
string line;
std::regex pattern(R"(mul\((\d+),(\d+)\))");
while (infile.good()) {
getline(infile, line);
if (line.empty()) continue;
auto begin = std::sregex_iterator(line.begin(), line.end(), pattern);
auto end = std::sregex_iterator();
for (auto it = begin; it != end; it++) {
std::smatch match = *it;
int x = std::stoi(match.str(1));
int y = std::stoi(match.str(2));
total += x * y;
}
}
infile.close();
std::cout << total << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment