Unable to load image

Day 18 AoC: A nice break :marseybeanrelieved:

This one was very easy compared to the last two days

10
Jump in the discussion.

No email address required.

Finally another problem that bruteforce chads can solve in few milliseconds! I had to imprecate a lot because of a stupid unsigned integer underflow (C++chads truly can't stop winning) and before founding it I implemented 2+1 counting methods plus a forth one plagiarized from Snakes, that's why I store two representations of the universe at the same time

:#marseyretardchad::#marseydrsneks::!#marseyretardchad:

![](/images/1671383813697684.webp)

Jump in the discussion.

No email address required.

There's constexpr for compile time known constants instead of the preprocessor #define

Jump in the discussion.

No email address required.

:#marseyhijab:

Jump in the discussion.

No email address required.

Cleaned up per usual. For the actual live solve I had unrolled loops because I can type faster than I can think. Stuff like this:

if (c[0]+1,c[1],c[2]) in cubes: sides -= 1
if (c[0]-1,c[1],c[2]) in cubes: sides -= 1
if (c[0],c[1]+1,c[2]) in cubes: sides -= 1
if (c[0],c[1]-1,c[2]) in cubes: sides -= 1
if (c[0],c[1],c[2]+1) in cubes: sides -= 1
if (c[0],c[1],c[2]-1) in cubes: sides -= 1

![](/images/16713962212272782.webp)

Jump in the discussion.

No email address required.

Pretty easy today. Part one as you would do it and part two as a bfs that will stop if it traverse into a cubes and counts +1 to the counter of sides facing the water.


#include <iostream>
#include <tuple>
#include <set>
#include <string>
#include <fstream>
#include <sstream>
#include <format>
#include <vector>
#include <queue>
#include <map>

struct coordinate {
	int x;
	int y;
	int z;

	coordinate operator+(const coordinate r) const {
		return {x + r.x, y + r.y, z + r.z};
	}

	auto operator<=>(const coordinate&) const = default;
};

typedef std::set<coordinate> set_type;

std::vector<coordinate> dirs{ { {0,0,1},{0,0,-1},{0,1,0},{0,-1,0},{1,0,0},{-1,0,0} } };

int count_neigbors(coordinate coord, const set_type& set) {
	int count{ 0 };
	for (auto dir : dirs) {
		if (set.contains(coord + dir)) count++;
	}
	return count;
}

int main()
{
	std::fstream file("input.txt");
	std::string buf;

	set_type cubes;

	int max_dimension{ INT_MIN };
	int min_dimension{ INT_MAX };

	while (std::getline(file, buf)) {
		int x, y, z;
		char c;
		std::istringstream iss( buf );
		iss >> x >> c >> y >> c >> z;
		max_dimension = std::max({ x, y, z, max_dimension });
		min_dimension = std::min({ x, y, z, min_dimension });
		cubes.insert({x,y,z});
	}
	int total{0};
	for (auto it = cubes.cbegin(); it != cubes.cend(); ++it) {
		total += 6 - count_neigbors(*it, cubes);
	}
	std::cout << "Part One: " << total << '\n';

	// We need to be able to "walk" around the entire cube area
	++max_dimension;
	--min_dimension;

	set_type explored;
	std::queue<coordinate> q;
	int result{ 0 };
	
	coordinate start { 0, 0, 0 };
	q.push(start);

	while (!q.empty()) {
		auto& cur = q.front();
		q.pop();
		if (explored.find(cur) != explored.end()) continue;
		explored.insert(cur);
		for (const auto& dir : dirs) {
			coordinate next = cur + dir;
			if (next.x > max_dimension || next.y > max_dimension || next.z > max_dimension ||
				next.x < min_dimension || next.y < min_dimension || next.z < min_dimension)
				continue;
			if (cubes.contains(next)) {
				result += 1;
			}
			else {
				q.push(next);
			}
		}
	} 
	std::cout << "Part Two " << result << '\n';
}

Jump in the discussion.

No email address required.

I don't have enough spoons to read this shit

Jump in the discussion.

No email address required.

Today's challenge gave me leeway to be lazy and retarded, so lazy and retarded I shall be.

foo = []
with open('day18_input.txt', 'r') as inp:
    foo = inp.read().split('\n')

cube_grid = [[[False for x in range(21)] for y in range(21)] for z in range(21)]
n = 0
for f in foo:
    f = [int(i) for i in f.split(',')]
    n_delta = 0
    for i in [[f[0]+1,f[1],f[2]],[f[0]-1,f[1],f[2]],[f[0],f[1]+1,f[2]],[f[0],f[1]-1,f[2]],[f[0],f[1],f[2]+1],[f[0],f[1],f[2]-1]]:
        if cube_grid[i[0]][i[1]][i[2]]:
            n_delta -= 1
        else:
            n_delta += 1
    cube_grid[f[0]][f[1]][f[2]] = True
    n += n_delta
print(n)

visited = [[[False for x in range(21)] for y in range(21)] for z in range(21)]
check = [[0,0,0]]
while(len(check) > 0):
    f = check[0]
    check = check[1:]
    for i in [[f[0]+1,f[1],f[2]],[f[0]-1,f[1],f[2]],[f[0],f[1]+1,f[2]],[f[0],f[1]-1,f[2]],[f[0],f[1],f[2]+1],[f[0],f[1],f[2]-1]]:
        if 20 >= i[0] >= 0 and 20 >= i[1] >= 0 and 20 >= i[2] >= 0 and not cube_grid[i[0]][i[1]][i[2]] and not visited[i[0]][i[1]][i[2]]:
            check.append(i)
            visited[i[0]][i[1]][i[2]] = True

for z in range(21):
    for y in range(21):
        for x in range(21):
            if not cube_grid[x][y][z] and not visited[x][y][z]:
                f = [x,y,z]
                for i in [[f[0]+1,f[1],f[2]],[f[0]-1,f[1],f[2]],[f[0],f[1]+1,f[2]],[f[0],f[1]-1,f[2]],[f[0],f[1],f[2]+1],[f[0],f[1],f[2]-1]]:
                    if 20 >= i[0] >= 0 and 20 >= i[1] >= 0 and 20 >= i[2] >= 0 and cube_grid[i[0]][i[1]][i[2]]:
                        n -= 1
print(n)
Jump in the discussion.

No email address required.

Had to increase python's recursion limit to 15 000 :marseysweating:

![](/images/1671377039774784.webp)

Jump in the discussion.

No email address required.

phew, that let me catch up from the day 16 frickery and day 17 tedium

![](/images/16713974879836175.webp)

Jump in the discussion.

No email address required.

:#marseymormon:

Jump in the discussion.

No email address required.

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.