From 0cbd6d36814a0ae5974d810be58d61ff0b312d14 Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Sun, 15 Dec 2024 01:49:40 -0600 Subject: [PATCH] 2024 day15 --- 2024/day15/input.txt | 0 2024/day15/input.txt.h | 15 +++++++++++ 2024/day15/sample1.txt | 10 ++++++++ 2024/day15/sample1.txt.h | 15 +++++++++++ 2024/day15/solution.c | 54 ++++++++++++++++++++++++++++++++++++++++ input_dreamcast.inc | 10 ++++++++ memory.c | 7 ++++++ memory.h | 1 + runner.inc | 7 ++++++ solutions.mk | 5 +++- 10 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 2024/day15/input.txt create mode 100644 2024/day15/input.txt.h create mode 100644 2024/day15/sample1.txt create mode 100644 2024/day15/sample1.txt.h create mode 100644 2024/day15/solution.c diff --git a/2024/day15/input.txt b/2024/day15/input.txt new file mode 100644 index 0000000..e69de29 diff --git a/2024/day15/input.txt.h b/2024/day15/input.txt.h new file mode 100644 index 0000000..f37ce2b --- /dev/null +++ b/2024/day15/input.txt.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +#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 diff --git a/2024/day15/sample1.txt b/2024/day15/sample1.txt new file mode 100644 index 0000000..8163605 --- /dev/null +++ b/2024/day15/sample1.txt @@ -0,0 +1,10 @@ +######## +#..O.O.# +##@.O..# +#...O..# +#.#.O..# +#...O..# +#......# +######## + +<^^>>>vv>v<< diff --git a/2024/day15/sample1.txt.h b/2024/day15/sample1.txt.h new file mode 100644 index 0000000..fef79f3 --- /dev/null +++ b/2024/day15/sample1.txt.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +#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 diff --git a/2024/day15/solution.c b/2024/day15/solution.c new file mode 100644 index 0000000..bb65eff --- /dev/null +++ b/2024/day15/solution.c @@ -0,0 +1,54 @@ +#include + +#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; +} diff --git a/input_dreamcast.inc b/input_dreamcast.inc index 240e1ae..17b93d4 100644 --- a/input_dreamcast.inc +++ b/input_dreamcast.inc @@ -39,6 +39,8 @@ #include "2024/day13/input.txt.h" #include "2024/day14/sample1.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] = { { @@ -155,6 +157,12 @@ static struct start_size sample[][2] = { { ( char *)&_binary_2024_day14_sample1_txt_start, (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[] = { @@ -196,4 +204,6 @@ static struct start_size input[] = { (uint32_t)&_binary_2024_day13_input_txt_size }, { ( char *)&_binary_2024_day14_input_txt_start, (uint32_t)&_binary_2024_day14_input_txt_size }, + { ( char *)&_binary_2024_day15_input_txt_start, + (uint32_t)&_binary_2024_day15_input_txt_size }, }; diff --git a/memory.c b/memory.c index 3753e14..fc68db0 100644 --- a/memory.c +++ b/memory.c @@ -15,3 +15,10 @@ void memory_set_int(int * buf, int c, int length) 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]; + } +} diff --git a/memory.h b/memory.h index cba25df..f8c7995 100644 --- a/memory.h +++ b/memory.h @@ -6,6 +6,7 @@ extern "C" { void memory_set_char(char * buf, char 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 } diff --git a/runner.inc b/runner.inc index 3c1c10d..a731291 100644 --- a/runner.inc +++ b/runner.inc @@ -42,6 +42,8 @@ int64_t _2024_day14_part2(const char * input, int length); void _2024_day14_render(const struct font * font, const struct glyph * glyphs, 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[] = { { @@ -139,4 +141,9 @@ struct day_funcs solution[] = { {_2024_day14_part1, _2024_day14_part2}, _2024_day14_render, }, + { + 2024, 15, + {_2024_day15_part1, _2024_day15_part2}, + NULL, + }, }; diff --git a/solutions.mk b/solutions.mk index c2a302e..9217c94 100644 --- a/solutions.mk +++ b/solutions.mk @@ -60,4 +60,7 @@ DAY_OBJ = \ 2024/day14/sample1.txt.o \ 2024/day14/input.txt.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