diff --git a/src/days/15/Day15.cpp b/src/days/15/Day15.cpp index fa0c5f5..e9246ba 100644 --- a/src/days/15/Day15.cpp +++ b/src/days/15/Day15.cpp @@ -1,9 +1,31 @@ #include "Day15.h" Result Day15::Task1() { + Set sensors; + Set beacons; + + parseSystem(sensors, beacons); + return Day::Task1(); } Result Day15::Task2() { return Day::Task2(); -} \ No newline at end of file +} + +void Day15::parseSystem(Set &sensors, Set &beacons) { + for (const string &line : input){ + size_t xPos = line.find('x') + 2; + size_t yPos = line.find('y') + 2; + int64 sx = stoi(line.substr(xPos, line.find(',') - xPos)); + int64 sy = stoi(line.substr(yPos, line.find(':') - yPos)); + + xPos = line.find("is at") + 8; + yPos = line.find('y', xPos) + 2; + int64 bx = stoi(line.substr(xPos, line.find(',', xPos) - xPos)); + int64 by = stoi(line.substr(yPos)); + + sensors.insert({sx, sy}); + beacons.insert({bx, by}); + } +} diff --git a/src/days/15/Day15.h b/src/days/15/Day15.h index e2b8133..bc39836 100644 --- a/src/days/15/Day15.h +++ b/src/days/15/Day15.h @@ -3,6 +3,14 @@ #include "../../Day.h" class Day15 : public Day { + typedef pair Point; + struct hashFunction { + size_t operator()(const Point &p) const { + return p.first ^ p.second; + } + }; + typedef unordered_set Set; + void parseSystem(Set&, Set&); protected: Result Task1() override; diff --git a/src/util.h b/src/util.h index e329b32..12596ac 100644 --- a/src/util.h +++ b/src/util.h @@ -6,16 +6,18 @@ #include #include #include +#include #include #include #include typedef uint64_t uint64; +typedef int64_t int64; using std::stoi, std::to_string; using std::cout, std::endl; -using std::string, std::vector, std::set, std::pair, std::map; -using std::list; +using std::string, std::vector, std::pair, std::map; +using std::list, std::set, std::unordered_set; using std::priority_queue; inline vector findAll(const string& data, const string& toSearch){