diff --git a/include/aoc.hpp b/include/aoc.hpp index 018128f..147ca4e 100644 --- a/include/aoc.hpp +++ b/include/aoc.hpp @@ -1,6 +1,7 @@ #pragma once -#include +#include +#include typedef long long ll; typedef unsigned long long ull; @@ -15,6 +16,15 @@ template struct Coord { this->y = y; } + static inline const std::array, 4> units() { + return { + Coord(0, 1), + Coord(1, 0), + Coord(0, -1), + Coord(-1, 0), + }; + } + Coord operator-() { return {-this->x, -this->y}; } Coord &operator+=(const Coord &other) { @@ -40,27 +50,6 @@ template struct Coord { y /= other; return *this; } - - std::vector> nearby(const Coord &cMin, const Coord &cMax) { - std::vector> ret; - const T xMin = std::max(this->x - 1, cMin.x); - const T xMax = std::min(this->x + 1, cMax.x); - const T yMin = std::max(this->y - 1, cMin.y); - const T yMax = std::min(this->y + 1, cMax.y); - for (T x = xMin; x <= xMax; x++) { - for (T y = yMin; y <= yMax; y++) { - Coord xy(x, y); - if (*this != xy) { - ret.push_back(xy); - } - } - } - return ret; - } - - std::vector> nearby(const Coord &cMax) { - return this->nearby(Coord(), cMax); - } }; template