2024 day15
This commit is contained in:
parent
7e2d115e36
commit
0cbd6d3681
0
2024/day15/input.txt
Normal file
0
2024/day15/input.txt
Normal file
15
2024/day15/input.txt.h
Normal file
15
2024/day15/input.txt.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern uint32_t _binary_2024_day15_input_txt_start __asm("_binary_2024_day15_input_txt_start");
|
||||||
|
extern uint32_t _binary_2024_day15_input_txt_end __asm("_binary_2024_day15_input_txt_end");
|
||||||
|
extern uint32_t _binary_2024_day15_input_txt_size __asm("_binary_2024_day15_input_txt_size");
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
10
2024/day15/sample1.txt
Normal file
10
2024/day15/sample1.txt
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
########
|
||||||
|
#..O.O.#
|
||||||
|
##@.O..#
|
||||||
|
#...O..#
|
||||||
|
#.#.O..#
|
||||||
|
#...O..#
|
||||||
|
#......#
|
||||||
|
########
|
||||||
|
|
||||||
|
<^^>>>vv<v>>v<<
|
15
2024/day15/sample1.txt.h
Normal file
15
2024/day15/sample1.txt.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern uint32_t _binary_2024_day15_sample1_txt_start __asm("_binary_2024_day15_sample1_txt_start");
|
||||||
|
extern uint32_t _binary_2024_day15_sample1_txt_end __asm("_binary_2024_day15_sample1_txt_end");
|
||||||
|
extern uint32_t _binary_2024_day15_sample1_txt_size __asm("_binary_2024_day15_sample1_txt_size");
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
54
2024/day15/solution.c
Normal file
54
2024/day15/solution.c
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
#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;
|
||||||
|
}
|
@ -39,6 +39,8 @@
|
|||||||
#include "2024/day13/input.txt.h"
|
#include "2024/day13/input.txt.h"
|
||||||
#include "2024/day14/sample1.txt.h"
|
#include "2024/day14/sample1.txt.h"
|
||||||
#include "2024/day14/input.txt.h"
|
#include "2024/day14/input.txt.h"
|
||||||
|
#include "2024/day15/sample1.txt.h"
|
||||||
|
#include "2024/day15/input.txt.h"
|
||||||
|
|
||||||
static struct start_size sample[][2] = {
|
static struct start_size sample[][2] = {
|
||||||
{
|
{
|
||||||
@ -155,6 +157,12 @@ static struct start_size sample[][2] = {
|
|||||||
{ ( char *)&_binary_2024_day14_sample1_txt_start,
|
{ ( char *)&_binary_2024_day14_sample1_txt_start,
|
||||||
(uint32_t)&_binary_2024_day14_sample1_txt_size },
|
(uint32_t)&_binary_2024_day14_sample1_txt_size },
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
{ ( char *)&_binary_2024_day15_sample1_txt_start,
|
||||||
|
(uint32_t)&_binary_2024_day15_sample1_txt_size },
|
||||||
|
{ ( char *)&_binary_2024_day15_sample1_txt_start,
|
||||||
|
(uint32_t)&_binary_2024_day15_sample1_txt_size },
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct start_size input[] = {
|
static struct start_size input[] = {
|
||||||
@ -196,4 +204,6 @@ static struct start_size input[] = {
|
|||||||
(uint32_t)&_binary_2024_day13_input_txt_size },
|
(uint32_t)&_binary_2024_day13_input_txt_size },
|
||||||
{ ( char *)&_binary_2024_day14_input_txt_start,
|
{ ( char *)&_binary_2024_day14_input_txt_start,
|
||||||
(uint32_t)&_binary_2024_day14_input_txt_size },
|
(uint32_t)&_binary_2024_day14_input_txt_size },
|
||||||
|
{ ( char *)&_binary_2024_day15_input_txt_start,
|
||||||
|
(uint32_t)&_binary_2024_day15_input_txt_size },
|
||||||
};
|
};
|
||||||
|
7
memory.c
7
memory.c
@ -15,3 +15,10 @@ void memory_set_int(int * buf, int c, int length)
|
|||||||
buf[i] = c;
|
buf[i] = c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void memory_copy_char(char * src, int length, char * dst)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < length; i += 1) {
|
||||||
|
dst[i] = src[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
1
memory.h
1
memory.h
@ -6,6 +6,7 @@ extern "C" {
|
|||||||
|
|
||||||
void memory_set_char(char * buf, char c, int length);
|
void memory_set_char(char * buf, char c, int length);
|
||||||
void memory_set_int(int * buf, int c, int length);
|
void memory_set_int(int * buf, int c, int length);
|
||||||
|
void memory_copy_char(char * src, int length, char * dst);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,8 @@ int64_t _2024_day14_part2(const char * input, int length);
|
|||||||
void _2024_day14_render(const struct font * font,
|
void _2024_day14_render(const struct font * font,
|
||||||
const struct glyph * glyphs,
|
const struct glyph * glyphs,
|
||||||
const void * maple_ft0_data);
|
const void * maple_ft0_data);
|
||||||
|
int64_t _2024_day15_part1(const char * input, int length);
|
||||||
|
int64_t _2024_day15_part2(const char * input, int length);
|
||||||
|
|
||||||
struct day_funcs solution[] = {
|
struct day_funcs solution[] = {
|
||||||
{
|
{
|
||||||
@ -139,4 +141,9 @@ struct day_funcs solution[] = {
|
|||||||
{_2024_day14_part1, _2024_day14_part2},
|
{_2024_day14_part1, _2024_day14_part2},
|
||||||
_2024_day14_render,
|
_2024_day14_render,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
2024, 15,
|
||||||
|
{_2024_day15_part1, _2024_day15_part2},
|
||||||
|
NULL,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
@ -60,4 +60,7 @@ DAY_OBJ = \
|
|||||||
2024/day14/sample1.txt.o \
|
2024/day14/sample1.txt.o \
|
||||||
2024/day14/input.txt.o \
|
2024/day14/input.txt.o \
|
||||||
2024/day14/render.o \
|
2024/day14/render.o \
|
||||||
2024/day14/solution.o
|
2024/day14/solution.o \
|
||||||
|
2024/day15/sample1.txt.o \
|
||||||
|
2024/day15/input.txt.o \
|
||||||
|
2024/day15/solution.o
|
||||||
|
Loading…
x
Reference in New Issue
Block a user