Compare commits

..

2 commits

Author SHA1 Message Date
eriedaberrie 9984b274d2 2024 day 20 2024-12-19 22:13:32 -08:00
eriedaberrie ed3742c0c9 Remove nearby and add units to util file 2024-12-19 22:13:25 -08:00
3 changed files with 11 additions and 22 deletions

View file

@ -2,13 +2,6 @@
#include <bits/stdc++.h> #include <bits/stdc++.h>
using namespace std; using namespace std;
const array<icoord, 4> directions = {
icoord(-1, 0),
icoord(1, 0),
icoord(0, -1),
icoord(0, 1),
};
void rec(icoord c, unordered_map<icoord, int> &m, int score) { void rec(icoord c, unordered_map<icoord, int> &m, int score) {
if (!m.contains(c)) { if (!m.contains(c)) {
return; return;
@ -20,7 +13,7 @@ void rec(icoord c, unordered_map<icoord, int> &m, int score) {
} }
s = score; s = score;
for (auto dir : directions) { for (auto dir : icoord::units()) {
rec(c + dir, m, score + 1); rec(c + dir, m, score + 1);
} }
} }

View file

@ -2,13 +2,6 @@
#include <bits/stdc++.h> #include <bits/stdc++.h>
using namespace std; using namespace std;
const array<icoord, 4> directions = {
icoord(-1, 0),
icoord(1, 0),
icoord(0, -1),
icoord(0, 1),
};
void rec(icoord c, unordered_map<icoord, int> &m, int score) { void rec(icoord c, unordered_map<icoord, int> &m, int score) {
if (!m.contains(c)) { if (!m.contains(c)) {
return; return;
@ -20,7 +13,7 @@ void rec(icoord c, unordered_map<icoord, int> &m, int score) {
} }
s = score; s = score;
for (auto dir : directions) { for (auto dir : icoord::units()) {
rec(c + dir, m, score + 1); rec(c + dir, m, score + 1);
} }
} }

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <array> #include <array>
#include <functional>
typedef long long ll; typedef long long ll;
typedef unsigned long long ull; typedef unsigned long long ull;
@ -15,12 +16,14 @@ template <typename T> struct Coord {
this->y = y; this->y = y;
} }
static inline const std::array<Coord<T>, 4> units = { static inline const std::array<Coord<T>, 4> units() {
return {
Coord<T>(0, 1), Coord<T>(0, 1),
Coord<T>(1, 0), Coord<T>(1, 0),
Coord<T>(0, -1), Coord<T>(0, -1),
Coord<T>(-1, 0), Coord<T>(-1, 0),
}; };
}
Coord<T> operator-() { return {-this->x, -this->y}; } Coord<T> operator-() { return {-this->x, -this->y}; }