Added older advents

This commit is contained in:
Jos van Goor 2022-12-01 13:46:47 +01:00
parent 8db2505049
commit 9cf858b860
78 changed files with 13807 additions and 0 deletions

View file

@ -0,0 +1,50 @@
118, 274
102, 101
216, 203
208, 251
309, 68
330, 93
91, 179
298, 278
201, 99
280, 272
141, 312
324, 290
41, 65
305, 311
198, 68
231, 237
164, 224
103, 189
216, 207
164, 290
151, 91
166, 250
129, 149
47, 231
249, 100
262, 175
299, 237
62, 288
228, 219
224, 76
310, 173
80, 46
312, 65
183, 158
272, 249
57, 141
331, 191
163, 359
271, 210
142, 137
349, 123
55, 268
160, 82
180, 70
231, 243
133, 353
246, 315
164, 206
229, 97
268, 94

View file

@ -0,0 +1,125 @@
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Point
{
size_t x;
size_t y;
Point()
: x(0), y(0)
{ }
Point(size_t x, size_t y)
: x(x), y(y)
{ }
};
istream &operator>>(istream& in, Point &point)
{
cin >> point.x;
cin.ignore(); // ignore ','
cin >> point.y;
return in;
}
inline size_t manhattan_distance(Point const &p1, Point const &p2)
{
return (p1.x > p2.x ? p1.x - p2.x : p2.x - p1.x)
+ (p1.y > p2.y ? p1.y - p2.y : p2.y - p1.y);
}
int closest(Point location, vector<Point> const &points)
{
int index = -1;
size_t mindist = std::numeric_limits<size_t>::max();
for (size_t idx = 0; idx != points.size(); ++idx)
{
size_t distance = manhattan_distance(location, points[idx]);
if (distance == mindist)
index = -1;
else if (distance < mindist)
{
mindist = distance;
index = idx;
}
}
return index;
}
int main()
{
size_t width = 0;
size_t height = 0;
vector<Point> points;
while(!cin.eof())
{
Point point;
cin >> point;
points.push_back(point);
width = max(width, point.x + 1);
height = max(height, point.y + 1);
}
cout << "grid size: " << width << " x " << height << "\n";
vector<int> counts(points.size(), 0);
for (size_t idx = 0; idx != width; ++idx)
{
for (size_t idy = 0; idy != height; ++idy)
{
int index = closest(Point{idx, idy}, points);
if (index == -1) continue;
++counts[index];
}
}
// if a class hits the edge its infinite.
// we check highest and lowers rows first.
for (size_t idx = 0; idx != width; ++idx)
{
int index = closest(Point{idx, 0}, points);
int index2 = closest(Point{idx, height - 1}, points);
if (index != -1)
counts[index] = -1;
if (index2 != -1)
counts[index2] = -1;
}
//side rows
for (size_t idx = 0; idx != height; ++idx)
{
int index = closest(Point{0, idx}, points);
int index2 = closest(Point{width - 1, idx}, points);
if (index != -1)
counts[index] = -1;
if (index2 != -1)
counts[index2] = -1;
}
size_t maxclass = 0;
int space = counts[0];
for (size_t idx = 1; idx != counts.size(); ++idx)
{
if (counts[idx] > space)
{
space = counts[idx];
maxclass = idx;
}
}
cout << "biggest class is " << maxclass << " with a size of " << space << "\n";
}

View file

@ -0,0 +1,73 @@
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Point
{
size_t x;
size_t y;
Point()
: x(0), y(0)
{ }
Point(size_t x, size_t y)
: x(x), y(y)
{ }
};
istream &operator>>(istream& in, Point &point)
{
cin >> point.x;
cin.ignore(); // ignore ','
cin >> point.y;
return in;
}
inline size_t manhattan_distance(Point const &p1, Point const &p2)
{
return (p1.x > p2.x ? p1.x - p2.x : p2.x - p1.x)
+ (p1.y > p2.y ? p1.y - p2.y : p2.y - p1.y);
}
int main()
{
size_t width = 0;
size_t height = 0;
vector<Point> points;
while(!cin.eof())
{
Point point;
cin >> point;
points.push_back(point);
width = max(width, point.x + 1);
height = max(height, point.y + 1);
}
size_t region_size = 0;
size_t distance_limit = 10000;
for (size_t idx = 0; idx != width; ++idx)
{
for (size_t idy = 0; idy != height; ++idy)
{
size_t sum = 0;
Point current {idx, idy};
for_each(points.begin(), points.end(), [&](Point const &point)
{
sum += manhattan_distance(current, point);
});
if (sum < distance_limit)
region_size++;
}
}
cout << "region size: " << region_size << "\n";
}