55 lines
1.1 KiB
C
55 lines
1.1 KiB
C
#include <stdint.h>
|
|
|
|
#include "cartesian.h"
|
|
#include "memory.h"
|
|
|
|
// struct cartesian_neighbor;
|
|
|
|
static bool move(char * room,
|
|
int width, int height,
|
|
int x, int y,
|
|
enum cartesian_direction direction)
|
|
{
|
|
const struct cartesian_neighbor * dir = &cartesian_neighbor[direction];
|
|
|
|
int nx = x + dir->x;
|
|
int ny = y + dir->y;
|
|
char n = room[ny * width + nx];
|
|
switch (n) {
|
|
case '#':
|
|
return false;
|
|
case 'O':
|
|
if (!move(room, width, height, nx, ny, direction))
|
|
return false;
|
|
[[fallthrough]];
|
|
default:
|
|
{
|
|
char c = room[y * width + x];
|
|
room[y * width + x] = '.';
|
|
room[ny * width + nx] = c;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
static enum cartesian_direction parse_direction(char c)
|
|
{
|
|
switch (c) {
|
|
case '<': return CARTESIAN_LEFT;
|
|
case '>': return CARTESIAN_RIGHT;
|
|
case '^': return CARTESIAN_UP;
|
|
case 'v': return CARTESIAN_DOWN;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
int64_t _2024_day15_part1(const char * input, int length)
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
int64_t _2024_day15_part2(const char * input, int length)
|
|
{
|
|
return -1;
|
|
}
|