master
Benjamin Kraft 2 years ago
parent 233addac52
commit d1863f213d
  1. 24
      src/days/15/Day15.cpp
  2. 8
      src/days/15/Day15.h
  3. 6
      src/util.h

@ -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();
}
}
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});
}
}

@ -3,6 +3,14 @@
#include "../../Day.h"
class Day15 : public Day {
typedef pair<int64, int64> Point;
struct hashFunction {
size_t operator()(const Point &p) const {
return p.first ^ p.second;
}
};
typedef unordered_set<Point, hashFunction> Set;
void parseSystem(Set&, Set&);
protected:
Result Task1() override;

@ -6,16 +6,18 @@
#include <tuple>
#include <iostream>
#include <set>
#include <unordered_set>
#include <map>
#include <list>
#include <queue>
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<size_t> findAll(const string& data, const string& toSearch){

Loading…
Cancel
Save