Compare commits

..

2 commits

Author SHA1 Message Date
eriedaberrie 4f20bfde3b 2024 day 20 2024-12-19 22:02:11 -08:00
eriedaberrie 7f1556b52d Remove nearby and add units to util file 2024-12-19 22:01:51 -08:00
3 changed files with 22 additions and 11 deletions

View file

@ -2,6 +2,13 @@
#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;
@ -13,7 +20,7 @@ void rec(icoord c, unordered_map<icoord, int> &m, int score) {
} }
s = score; s = score;
for (auto dir : icoord::units()) { for (auto dir : directions) {
rec(c + dir, m, score + 1); rec(c + dir, m, score + 1);
} }
} }

View file

@ -2,6 +2,13 @@
#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;
@ -13,7 +20,7 @@ void rec(icoord c, unordered_map<icoord, int> &m, int score) {
} }
s = score; s = score;
for (auto dir : icoord::units()) { for (auto dir : directions) {
rec(c + dir, m, score + 1); rec(c + dir, m, score + 1);
} }
} }

View file

@ -1,7 +1,6 @@
#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;
@ -16,14 +15,12 @@ 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}; }