From 69febabee8b5c54baa3043b39c9e60efb3c38784 Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Mon, 16 Dec 2024 01:39:42 -0600 Subject: [PATCH] 2024 day16 (incomplete) --- 2024/day16/input.txt | 141 +++++++++++++++++++++++++++++++++++++++ 2024/day16/input.txt.h | 15 +++++ 2024/day16/sample1.txt | 17 +++++ 2024/day16/sample1.txt.h | 15 +++++ 2024/day16/solution.c | 109 ++++++++++++++++++++++++++++++ aoc.mk | 3 +- bfs.c | 75 +++++++++++++++++++++ bfs.h | 23 +++++++ dijkstra.c | 70 +++++++++++++++++++ dijkstra.h | 25 +++++++ heap.c | 48 +++++++++++++ heap.h | 13 +++- input_dreamcast.inc | 10 +++ linear_algebra.c | 27 -------- memory.c | 13 +++- memory.h | 3 +- runner.c | 2 +- runner.inc | 7 ++ solutions.mk | 5 +- test/run.sh | 20 ++++++ test/runner.h | 27 ++++++++ test/test_dijkstra.c | 76 +++++++++++++++++++++ test/test_heap.c | 35 ++++++++++ test/test_memory | Bin 0 -> 29616 bytes test/test_memory.c | 23 +++++++ 25 files changed, 769 insertions(+), 33 deletions(-) create mode 100644 2024/day16/input.txt create mode 100644 2024/day16/input.txt.h create mode 100644 2024/day16/sample1.txt create mode 100644 2024/day16/sample1.txt.h create mode 100644 2024/day16/solution.c create mode 100644 bfs.c create mode 100644 bfs.h create mode 100644 dijkstra.c create mode 100644 dijkstra.h create mode 100644 test/run.sh create mode 100644 test/runner.h create mode 100644 test/test_dijkstra.c create mode 100644 test/test_heap.c create mode 100755 test/test_memory create mode 100644 test/test_memory.c diff --git a/2024/day16/input.txt b/2024/day16/input.txt new file mode 100644 index 0000000..2e1e1ec --- /dev/null +++ b/2024/day16/input.txt @@ -0,0 +1,141 @@ +############################################################################################################################################# +#.............#...#...........#...#...................#.........#...........#...................................#.............#.......#....E# +#.#####.#####.#.#.#.###.#####.#.#.#.#.#########.#####.#.#######.#.#########.#######.###.###.###.#.#######.#.###.#.#########.#.#####.#.#.#.#.# +#.#...#...#.#...#.#...#.....#.#.#.#.#.....#.....#...#...#.......#...#.....#.....#...#.#.....#.#.#.#.....#.#...#.#.#.#.......#...#...#.#.#.#.# +###.#.#.#.#.###.#.###.#.###.#.#.#.#.#.###.#.#####.#######.#########.###.#######.#.###.#######.#.#.#####.#.###.#.#.#.#.#########.#.###.#.#.#.# +#...#.#.#.#...#.....#...#...#...#...#.#.#...#...#.......#.........#...#.........#.#.#.........#.#.......#.#...#.#.#.#.....#.....#.#...#.#.#.# +#.###.###.#.###.#########.#####.#####.#.#####.#.#.#.#############.#.#.#####.#####.#.#.###.###.#.###.#####.#.###.#.#.#####.###.###.#.###.#.### +#.#.......#.....#.....#...#.....#.....#.......#...#.............#.#.#.....#.#.....#.#...#...#.#.#...#.....#.#.#.#.....#.#...#...#.#.#...#...# +#.#########.###.#.#.###.###.###.#.#####.#################.#######.#.#####.#.#.#####.###.###.#.#.###.#.#####.#.#.#####.#.###.###.#.###.#.#.#.# +#.#...#.....#.#...#...#.#.#.#.#.#.........#.............#...#.....#.....#.#.#...#...#...#...#.#...#.#.#...#...#...........#.#.............#.# +#.#.#.#####.#.#.#####.#.#.#.#.#.#######.#.#.#######.###.###.#.#######.###.#.###.#.#.#.#.#.###.###.###.#.#.###.###########.#.#.#####.###.#.#.# +#...#.....#...#...#...#.#.#...#.........#...#.....#...#.#...#...#.#...#...#.....................#...#...#...#.......#...#.#.#.#.......#.#...# +#.#######.#####.###.#.#.#.#.#####.#####.#####.###.#####.#.#####.#.#.###.#########.#.#.#.###.#######.#.#.#.#####.#####.#.#.#.###.#.#####.#.### +#.#.....#.....#.#...#.#.#...#.....#...#.#.#...#.....#...#.....#.#...#...#.........#.#.....#.#.......#...#.......#.....#.#.#...#...#.....#...# +#.#.###.###.#.#.#.###.#.#.###.#####.#.#.#.#.#######.#.#######.#.###.#.###.###########.#.###.#.###########.#######.###.#.#.###.#.#.#.###.#.#.# +#...#.#.#...#...#.#...#.#...#.#.....#.#...#.....#.#...#.......#...#.#.#.#.......#.....#...#...#.........#...#.....#.#...#...#.#.#...#.....#.# +#####.#.###.#####.#.###.#####.#.###.#.#.#.#####.#.#.#####.###.###.###.#.#.#####.#.#####.#.#.###.#######.#####.#####.#.###.###.#.#.###.#####.# +#.....#.....#.....#...#.#.....#...#.#.#.....#.......#...#...#.#...#...#...#.......#.....#.#.#...#.............#.....#.#.#.#...#.#.#...#...#.# +#.#########.#.#######.#.#.#########.###.#####.#######.#.###.###.###.###.###.###.#.#.#####.#.#.#.#.#######.###.###.###.#.#.#.###.#.#.###.###.# +#.#.......#.#.......#.#...#.......#...#.#.........#...#...#...........#...#.......#.#...#.......#.........#.......#...#...#.....#.......#...# +#.#.#.###.#.#######.#######.#####.###.#.#.#.#####.#.#####.#.#########.###.#########.#.#.#.###########.#.###.###.#.#.###.#########.#######.#.# +#...#.#...#.#.....#.#.......#.........#.#.#.....#...#.....#...#.....#...#.#...#.....#.#.#...#.......#...#...#...#.....#.....#.......#.....#.# +#####.#.###.#####.#.#.###.###.#######.#.#.#####.#.###.#######.#.###.#.#.#.#.###.#.###.#.###.#######.#####.###.###.###.#####.#####.#.#.#####.# +#.....#...#.....#.#...#...#...#.......#.#.#.....#.#...#...#...#.#...#.#.....#...#.....#...#.......#.....#...#.#.....#...#.#.........#.....#.# +#.#.#######.###.#.#####.###.#.#.#######.#.###.#####.###.#.#####.#.###.#.#####.###.#######.#######.#.#.###.#.#.#########.#.#####.#.#######.#.# +#.#.#...........#...#...#...#...#.....#.#...#.......#...#.......#...#.....#...#.#...#...........#.#.#...........#.....#.#.#.....#.........#.# +#.#.#.#####.#######.#.#####.#####.###.#.###.#####.###.###########.#.#######.###.#.#.###.#####.###.#.###.#.#.###.#.###.#.#.#.###.#.#########.# +#.#.#...............#.....#.#.....#...#...#...#...#...#...#.....#.#...........#.#.#.....#.....#...#.#.#.....#...#...#.....#.#.....#.....#...# +#.#.#.#.#.#.#######.#####.#.#.#####.#####.###.#####.#####.#.###.#.#######.###.#.#.#####.#.#####.###.#.#######.#.###.#.#.#.#.#.#.#.###.###.### +#.#.#.#.#.#.......#.....#.#.#.....#.......#.#.....#...#...#...#.#.......#.#...#...#.....#.....#.#...#.......#.#...#.#.#.#...#.#.....#.......# +#.###.#.###.#####.#######.###.#.###########.#.#.#.###.#.#####.#.###.#####.#.###.###.###.#######.#.#.#####.#.#.#####.#.#.#####.#.###.#######.# +#.....#...#.....#...#...#...#.#.#.....#.....#...#...#.#.#.....#...#.#.....#.#.....#.#...#.....#.#...#...#.#.#.......#.........#...#.......#.# +#.#######.#.###.###.#.#.###.#.#.#.#.###.#.#.#####.###.#.#.#######.#.#.###.#.#####.#.###.#.###.#.#.###.#.#.#.#######.#########.#.#.#######.### +#.....#...#.....#.#...#...#.#.#.#.#.....#.#...#...#...#.#.....#.#.#.#...#.#...#...#...#.#.#...#.#.#...#.#.#...#...#.#.....#.............#...# +#####.#.#.#.#####.#######.#.#.#.#.#######.###.#.###.###.#####.#.#.###.#.#####.#######.###.#.###.#.#.###.#.###.#.#.###.###.#.###.###.#######.# +#.#...#.#.#.#...#...........#.#...#...#.#...#.#...#...#...#.#...#...#.#.#...#.#.....#.#...#.....#...#.....#...#.#.....#.#.#.......#.#.....#.# +#.#.###.#.#.###.#.###########.#.###.#.#.###.#.###.###.#.#.#.#.#.###.###.#.#.#.#.###.#.#.#############.#########.#######.#.###.#.###.#.###.#.# +#...#...#.#.#...#.#...........#.....#.#.#...#...#...#...#.#.#.#...#.#...#.#.....#.....#.#...#.........#.........#.......#...#.#.....#.#...#.# +#.###.#.###.#.###.#.#######.#.#######.#.#.#####.###.#####.#.#.#.###.#.#.#.#######.###.#.#.#.#####.#####.#########.#####.###.#.#.#####.#.###.# +#...#.#...#.#.....#.#.....#...#...#...#.#.#.#.....#...#...#.#.#...#.#.#.#...#.......#.#...#.....#...#...#.....#...#...#...#.....#.....#.#...# +###.#.###.#.#######.#.#########.#.###.#.#.#.#.###.#.###.###.#.#.#.#.#.#.###.#.#####.#####.#####.#.#.#.#####.#.#.#.#.#.###.###.#.#.#####.###.# +#...#.#...#.........#...........#...#...#.#.......#.....#...#.#.#.....#.#...#.....#.#...#.#.........#.#.....#.#.#...#.....#...#.#.#...#.....# +#.#.#.#.#########.#######.#########.###.#.#.#####.#######.###.###########.#######.#.#.#.###.#####.#.#.#.#####.#.#.#.#######.#.#.#.#.#.#####.# +#.#...#.#...............#.....#...#.#.#.#.#...#.#...#.......#...#.........#.#...#.#...#.....#...#...#.#.#...#.#.#.#...#.#...#.#.#...#.#.#...# +#.#.###.#.#######.#####.#.###.#.#.#.#.#.#.#.#.#.###.###.###.###.#.#########.#.#.#.#####.#####.#.#####.#.#.#.#.###.###.#.#.#####.###.#.#.#.### +#.#...#...#.......#...#.#.#...#.#.#.#...#.#.#.....#...#.#...#...#...#.#.......#.#...#...#.....#.........#.#.#.....#.......#...#.#.........#.# +#.#.#######.#########.#.#.#.#####.#.###.#.#.#####.###.#.#.#.#.#.###.#.#.#######.###.#####.#########.#####.#.#######.#####.#.#.#.#.#.###.###.# +#.#.#.....#.....#.....#.#.#.....#.#...#.#.#.....#.#...#...#.#.#.#...#.....#.....#...#...#.#...#.....#.....#...#.....#...#...#...#.....#.#...# +#.#.#.#.#.#####.#.#####.#.#####.#.#.#.#.#.#.###.###.#######.#.#.#.###.###.#.###.#.#.#.#.#.#.#.#.###.#######.#.#.#####.#.###########.#.#.#.#.# +#.#.#.#.................#.....#.#.#...#.#.#...#.....#.......#.#.#.#.....#.#.#...#.#.#.#...#.#.#.............#.#.#...#.#.........#.....#.#.#.# +#.#.#.#.#########.###.###.#####.#.#.#####.#.#####.###.#.#.###.###.#.#.#.###.#.###.###.#####.#.#.#.#############.###.#.#######.#.#.#.###.#.#.# +#.#.#.....#.....#.#.......#.....#.#.#.....#.#...#.....#...#...#...#.#.#.#...#...#.....#.....#.#...#...........#.#...#.#.....#.............#.# +#.#.###.#.###.###.###.#.###.#####.#.#.#######.#.#######.###.#.#.#####.#.#.#####.###########.#.#.###.#########.#.#.###.#.#.#.#.###.#.#.###.#.# +#.#.....#.......#...#...#.#.#.....#.#.#...#...#.......#...#.#.........#.#...#.#...#.........#.#.........#...#.#.#...#.#.#.#.#...#.#.#...#.#.# +#.#.###.###.###.#.#.###.#.#.###.#.#.#.#.#.#.#######.#.###.#.###.###.###.###.#.#.#.###.#######.#######.###.#.#.#.###.#.#.#.#.###.#.#.#.###.#.# +#.#...#.....#...#.#...#...#.#...#.#.#...#.#.......#.....#.#.#...#...#.#.........#...#.#.......#.....#.#...#.#.....#.#...#.#...#...#.#.....#.# +#.#.#.#.#####.#.#.###.#####.#.#####.#.###.#######.#.#.###.#.#.###.###.#########.###.#.#.#######.###.#.#.###.#####.#.#####.#.#######.#.#####.# +#.#.#.#.#.....#.....#.......#.#.....#...#...#...#.#.#.....#.#.#...#.....#.........#...#...#.....#.#.#...#.#...#.......#...#.................# +#.#.#.#.#####.###############.#.#######.#.#.###.#.#.###.###.#.#.#######.#.#.###########.###.#####.#.###.#.###.#########.#############.####### +#...#.#.....#...#.......#...#...#.......#.#...#.#.#...#.#.....#.#.......#.#.#.......#...#...#.....#...#.#...#.................#.....#.......# +###.#.#.###.#.#.#.#.###.###.#.#######.###.###.#.#.###.###.###.#.###.#.###.#.#.#.#.#.#.###.###.#######.#.#.#.#########.###.###.#.###.#.#####.# +#...#.#.#.#.#.#...#...#.....#.#.....#.#...#.#.#.#.#.#...#.#...#...#.......#...#...#.#.#.#.#.........#.#.#.#.#.......#.....#.#...#.#.#...#.#.# +#.#.#.#.#.#.#########.#####.#.#.###.###.###.#.#.#.#.###.#.#.#####.#.###########.###.#.#.#.###.#.#.#.#.#.###.#.#.###.###.#.#.#####.#.#.#.#.#.# +#.#.#.#...#.#.......#...#...#...#.#...#.#.......#...#.#.#...#.....#.#...#.....#.....#.#.#...#.#...#...#...#.#.#.#.#.#.#.#.#.......#.........# +#.###.###.#.#.#####.#.#.#.#######.#.#.#.###########.#.#.#####.#####.###.#.#.#####.###.#.###.###.#######.#.#.#.#.#.#.#.#.#.###.###.###.#.###.# +#.............#.#...#.#.#.#...#.....#.#...........#.#.#...........#...#...#.#...#.......#.#...#.........#.#...#.#.....#.#.#.................# +#.#####.#.###.#.#.###.#.#.#.#.#.###.#.###.#####.###.#.#########.#.###.#####.#.#.#######.#.###.###.#####.#.#.###.#######.#.#.###.###.#####.#.# +#.#.....#.....#...#...#.#.#.#.#...#.#...#.#...#.#...#.....#.......#.#...#...#.#...#...#.....#.#.......#.#.#...#.....#...#.#.#...#.......#.#.# +#.#.#####.#.###.#######.#.#.#####.#.###.#.#.#.#.#.###.#####.#######.###.#.###.###.#.#.#######.#######.###.###.#####.#.###.#.#.#####.###.#.#.# +#.............#.#...#.....#.....#.#.....#.#.#.#.#.#...#.....#.............#...#.#...#...#...#.......#...#.#...#...#.#.#.#...#.....#...#.#.#.# +###.#.###.###.#.#.#.#.###.#.#.#.#.#######.#.#.#.#.#.#.#.#####.#############.###.#######.#.#.#######.###.#.#.###.###.#.#.#########.#.###.#.### +#...#...#...#.....#.#...#.#.#.#...#.....#...#.#.....#.#...#.#.#...#.....#...#.......#.#...#.#.......#.....#...#...#...#.....#...#.#.....#...# +#.###.#.#.###.#####.###.#.###.#.#.#.###.#####.###########.#.#.#.###.#####.#.#.###.#.#.#####.#.#######.#######.###.#######.###.#.#.#.#######.# +#...#.#...#...#...#.#...#...#.#.#.#.#.#...#.#.#.....#.....#.#.#.#...#.....#.....#.#...#...#.#.#.....#.........#...........#...#...#.....#...# +###.#.###.#.#####.#.#.#####.#.###.#.#.###.#.#.#.###.#.#####.#.#.#.###.###.#######.###.#.#.#.#.#.###.#.###.#.#.#.#######.###.#######.###.#.### +#...#...#.#.#...#.#.#.#.#...#...#...#.....#...#.#.#...#.#...#...#.#.#.#.#...#.....#.#.#.#.#.#.#.#...#.#...#.#.#.#.......#...#.#.........#...# +#.#####.#.#.#.#.#.#.#.#.#.#####.#####.#####.###.#.#####.#.#.#.###.#.#.#.###.#.#####.#.#.#.#.#.#.###.#.#.###.#.#.#########.###.#.#.#.###.###.# +#.#.......#.#.#...#.#.#.#.#.....#...#.....#...#.#.........#...#...#.......#.#...#.......#.#...#.......#...#.#.#...........#...#.#.#...#.#...# +#.#.#####.#.#.#####.#.#.#.###.#.#.#######.###.#.#.#####.#######.#.#######.#.###.###############.#########.#.#.###.###########.#.#.#.#.#.#.#.# +#.#.#.......#...#...#.#.#.#...#...#...#...#...#.#.......#...#.#.#...#.....#.#...#...............#.#...#...#.#...#.#.........#...#.#.#...#...# +#.#.#.#######.#.#.###.#.#.#.###.###.#.#.#######.#.#######.#.#.#.#.#.###.###.#.###.#########.#####.#.#.#.#######.#.#.#.#####.#.###.#.#######.# +#.#.#...#.....#.......#...#...#.#...#...#.......#.........#...#...#...#.#...#...............#.....#.#...#...#.......#.#...#.#.#...#...#...#.# +#.#.###.#################.###.#.#.#######.#.#######.#################.#.#.###.#######.#####.#.###.#.#####.#.#.#########.#.#.###.###.###.#.#.# +#.#.#.#.....#.....#.....#.....#.#.....#.#.#.#.#.....#...#.........#...#.#.#...#...#.#.....#.#...#.#.......#.#.....#.....#.#.#...#...#...#...# +#.#.#.#####.#.###.#.###.#####.#######.#.#.#.#.#.#####.#.#.#######.#.###.#.#####.#.#.#.###.#.#.#.###########.#####.#.#####.#.#.###.###.#####.# +#.....#...#.......#...#.......#.......#...#.#.....#...#...#.......#.#...#.#.....#.#.#...#.#.#.#.......#...#...#.#...#...#.#...#.....#...#...# +#.#####.#.#######.#.###.#######.###########.#.#####.#######.#####.#.#####.#.#####.#.#.###.#.#.#######.#.#.#.#.#.#####.#.#.#########.###.#.#.# +#...#...#...#.....#.#...#.....#.....#.......#.#.#...#...#...#.....#.......#...#.#.#...#...#.#...#.....#.#...#...#.....#.#.....#.......#.....# +#####.#.###.#.#.###.#.#.#.###.#####.#.#######.#.#.#####.#.###.#############.#.#.#.#.###.#.#.###.#.#.#.#.#######.#.#####.#.###.#.###.#.#.#.#.# +#...#.#.....#.#.#...#.#.#.#.#.#.....#...........#.#.....#.#.#.#.............#.#.#.#...#.#.#.#...#.#.#.#.......#.#.#.........#.#.#.......#...# +#.#.#.#.#####.###.###.#.#.#.#.#.#####.###.###.#.#.#.###.#.#.#.###.#######.###.#.#.#####.#.#.###.#.#.#.#.#.#.#.#.###.#######.#.#.###.#######.# +#.#...#.......#...#...#.#...#.#.....#.#.#.....#...#...#...#.#...#.#...#.......#...#.....#.#...#.#.#.....#...#.#.....#.....#.#.#.........#...# +#.#####.#.###.#.###.#.#####.#.#####.#.#.#####.###.###.###.#.###.#.#.#.#.#######.###.#########.###.#####.#####.###########.#.#.#####.###.#.#.# +#.#...#.....#.#...#.#.#...#.#.....#.#.#.....#.#...#...#...#.#...#.#.#.#.......#.#...#.......#.#...#.#...#...#.#.........#...#.........#.#...# +#.#.#.#.#.###.###.#.#.#.#.#.#.###.#.#.#.###.#.#.###.###.###.#.#####.#.#.#.#.#.#.#.#.#.###.#.#.#.###.#.#.###.#.#.#######.#.#########.#.#.#.#.# +#.#.#...#.#.....#.#.....#...#...#.#.#...#...#...#...#...#...#.......#...#.#...#.#.#.#.#...#.#.#...#...#.....#.....#.....#...#.......#...#.#.# +#.#.###.#.#.#####.#############.#.#.#######.#####.#.#.###.#############.#.#.###.#.#.#.#.#.###.###.#.###.#.#.#######.#######.###.#.#.#######.# +#.#.#...#...#.....#.....#.....#.#.#...#...#.......#.#...#...#.........#...#.....#.#.#...#...#.....#.#...#.#.#.......#.....#...#.#.........#.# +#.#.#.###.###.#####.###.###.#.#.#####.#.#.#########.###.###.#.#####.#.#####.#####.#.#.#.###.#######.#####.#.#.#.#####.#######.###.#.###.#.#.# +#.#.#.#.#.#.#.#.......#.....#.#.....#...#.#.......#...#...#.#...#...#...#...#.....#.#...#.#...#...#.#...#.#.#.#.#...........#...#.#.....#...# +#.#.#.#.#.#.#.#.#####.###.#########.#####.#.###.###.#####.#.#.#.#.#######.###.#####.###.#.###.#.#.#.#.#.#.#.#.#.#.#######.#####.#.#.#######.# +#.#.........#.#.....#.#...#.......#.#.....#...#.....#.....#.....#.....#...#...#...#...#...#.#...#.#...#.#.#...#.#.....#...#.....#.#...#.#...# +#.#.#.###.#.#.###.###.#.###.###.###.#.#####.#########.#.#####.#######.#.###.###.#.#.#####.#.#####.#####.#.###.#.#####.#.###.#####.###.#.#.### +#...#.................#.#...#...#...#.....#.#.......#.#.#...#.....#...#.#.....#.#.#.....#.#.......#...#...#...#.#.....#.#...#...#.#.#.#.....# +#.#####.#####.#.###.#####.###.###.#.#####.###.#####.#.###.#.#####.#.#.#.#####.#.#######.#.###.#.#.#.#.#.#######.#######.#.###.#.#.#.#.####### +#...#.#.#...#.#...#.........#.....#.....#...#...#...#.....#...#.....#.#...#...#.......#.#.#...#.#...#...#.......#.......#.#...#.#...#.#.....# +###.#.#.#.#.#.###.###########.#.#####.#####.###.#.###########.#.#.#######.#.###.#.###.#.#.#.#.#########.#.#######.#####.#.###.#.#####.#.###.# +#...#.#...#.#...#.#.........#.#.#...#.#.....#...#.......#...#.#...#...#.........#...#.#...#.#.#...#...#.#.#...#.....#...#.....#...#...#...#.# +#.###.#####.###.###.###.#.#.#.#.#.#.#.#.#####.#########.#.#.#.#.###.#.#.#######.###.#######.###.#.#.#.#.#.#.#.#.###.#############.#.###.###.# +#.#...#.....#...#...#...#.#...#.#.#...#.......#.....#...#.#...#...#.#...#.....#...#.#.....#.....#.#.#...#.#.#.#.#...#.....#.....#.#.....#...# +#.###.#.###.#.###.#####.#.###.#.###############.###.#.###.#####.#.#.#######.#####.#.#.#.#.#######.#.###.#.#.###.#.###.###.#.###.#.#####.#.### +#.....#.#...#...#.#...#.#...#.#.#...........#.....#.#.#...#.....#...#.......#...#.....#.#.....#...#...#.#.#.#...#.....#.#.#.#.#.#.....#.#...# +#.#.#.#.###.###.#.#.#.#.###.###.#.###.###.#.#######.#.###.#.###.#####.###.###.#.#.#####.#####.#.#.###.#.#.#.#.#########.#.#.#.#.#####.###.#.# +#...#.#...#.....#.#.#.#.....#...#.......#.#.........#...#.#...#...#.....#.....#.....#...#.#.....#.#...#...#.#.....#.....#...#.#.....#...#.#.# +#####.###.#.#.###.#.#.#######.#########.#.#######.#####.#.###.#.#.#######.#######.#.#.###.#.#.#.#.#.#######.#####.#.###.#####.#.###.###.###.# +#.#.....#.#.#...#.#.#.........#.......#.#.#.....#.#...#.#...#...#.#.....#.#.......#...#.#.......#.#.#...#.......#...#...#.....#...#...#...#.# +#.#.#.###.#.###.#.#.###.#####.#.#.#####.#.#.###.###.#.#.#.#.#####.#.###.###.#####.###.#.#.#########.#.#.#.###.#######.#.#.###.###.#######.#.# +#...#.....#...#...#.....#...#.#.#.......#.#...#.#...#.....#.#.....#...#.....#...#.#.......#...#.....#.#.#...#.......#...#.#.#...#...#...#.#.# +#.###.###########.###.#.#.#.#.#.#########.###.#.#.#.#######.#.#######.#######.#.#.#########.#.#.#####.#.###.#.###.#.###.#.#.###.###.#.#.#.#.# +#.#.#.....#.......#.#.#.#.#.#.#.......#.....#.#...#...#.....#.#.....#.....#...#.#...........#.#...#...#...#.#...#.#.#...#.#.#...#.#...#.#...# +#.#.#####.#.#####.#.#.###.#.#######.#.#.#####.#####.#.###.###.#.###.###.#.#.###.#############.###.#######.#.#.#.#.#.#.###.#.#.###.#####.###.# +#...#...#.#...#.....#.....#.......#.........#.#.....#.#...#.#.#...#...#.#.....#.......#.....#...#...........#.#...#.#.#...#.#.#.......#.....# +###.#.#.#.###.#.###.#############.#.#######.#.#####.#.#.###.#.###.###.#.#########.###.#.#.#####.#.#####.#.###.#####.#.#.###.#.#.###.######### +#...#.#.#.#...#.#...#...........#.#.....#.......#...#...#...#...#.#.#.#...#.#.........#.#.......#...#...#.#.#.....#...#...#...#.#...#.....#.# +#####.#.#.#.###.#.###.###.#####.#.#####.#.#####.#.#.#####.#####.#.#.#.###.#.#.###########.###########.###.#.#####.#.#####.###.###.###.#.#.#.# +#...#.....#.#...#.....#...#...#.#.....#.#.#.....#.#.....#.....#...#...#.#.#.#...........#.................#...#...#.....#...#...#.....#.#.#.# +#.#.#.###.#.#.#.#######.###.#.#######.#.#.#.#####.#.#.#.#.###.#####.###.#.#.#########.#.#######.#.#####.#.###.#.#.#####.#.#.###.#######.#.#.# +#.#...#.....#.#.....#...#...#.........#.#...#.....#...#...#...........................#...#...#.#.#...#.....#.#.....#...#.#...#.....#...#.#.# +#.###.#.#.###.#.###.#.###.#.#########.#.#.###.#####.#####.#.#.#.###.#.#.###.#.#######.###.#.###.#.#.#.###.#.#.#.###.#.#.#.###.#####.#.###.#.# +#...#.#.....#.#...#.#.#...#.#...#...#.#...#.......#...#.#...#.#.#...#.#...#.#.....#...#...#.....#...#...#.....#.#...#.#.....#.....#.#.#.....# +#.#.#.###.#.#.#.#.#.###.###.#.#.#.#.#.###.#######.#.#.#.#.#.#.#.#.#######.#.#####.#.#.#.###.#####.#####.#.#####.#.#.#.#.#######.#.#.#.#.###.# +#.#.#.....#.#...#.#.....#.#.#.#...#.#...#...#.....#...#...#...#.#.......#.......#.#.#...#...#.........#.....#...#.#...#.#.....#.#.#.#.....#.# +#.#.#####.#.#.#.#.#######.#.#.#####.#####.#.#.#####.###.#.#.###.#######.#.#.#####.#.#.###.###########.#####.#.#.###.#.#.#.###.###.#.###.#.#.# +#.#.#...#.#.#.#.#...#.......#.....#.......#.#.#.....#...#.#.......#...#...#.#...........................#...#.#.....#...#...#.#...#.......#.# +###.#.#.#.#.#.#.###.###########.#.#####.#.#.#.#.#.#.###.#.#.#####.#.#.###.###.#####.###.#.#.###.#.#.###.#.###.#.###.#.#####.#.#.#######.###.# +#...#.#.....#.#...#.#...........#.#...#.....#.#.#.#...#.........................#.#.#...#...#...#.#.....#.#.....#...........#.#...#.#...#...# +#.#.#.###.#####.#.#.#.#######.###.#.#########.#.###.#.###.#.#####.#.#.###.#.#.#.#.#.#.#######.#########.#.###.###.#.#.#######.###.#.#.#.#.### +#.#.#.#...#.....#.#.#.#.....#.#...#...........#...#.........................#.#.#...#.#.#...#.#.............#...#.......#...#.....#...#.....# +#.###.#.#.#.#####.#.#.#####.#.#.###########.###.#.#.###.#.#.###.###.#.#.#.#.###.#.###.#.#.#.#.#.#.#.#.#####.###.###.#.#.#.#.#######.###.#.#.# +#S......#...#.....#.........#...............#...#.....#.......#.....#...#.......#.....#...#.....#...#.......#...........#.#.................# +############################################################################################################################################# diff --git a/2024/day16/input.txt.h b/2024/day16/input.txt.h new file mode 100644 index 0000000..42c8bc8 --- /dev/null +++ b/2024/day16/input.txt.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern uint32_t _binary_2024_day16_input_txt_start __asm("_binary_2024_day16_input_txt_start"); +extern uint32_t _binary_2024_day16_input_txt_end __asm("_binary_2024_day16_input_txt_end"); +extern uint32_t _binary_2024_day16_input_txt_size __asm("_binary_2024_day16_input_txt_size"); + +#ifdef __cplusplus +} +#endif diff --git a/2024/day16/sample1.txt b/2024/day16/sample1.txt new file mode 100644 index 0000000..bc61c57 --- /dev/null +++ b/2024/day16/sample1.txt @@ -0,0 +1,17 @@ +################# +#...#...#...#..E# +#.#.#.#.#.#.#.#.# +#.#.#.#...#...#.# +#.#.#.#.###.#.#.# +#...#.#.#.....#.# +#.#.#.#.#.#####.# +#.#...#.#.#.....# +#.#.#####.#.###.# +#.#.#.......#...# +#.#.###.#####.### +#.#.#...#.....#.# +#.#.#.#####.###.# +#.#.#.........#.# +#.#.#.#########.# +#S#.............# +################# diff --git a/2024/day16/sample1.txt.h b/2024/day16/sample1.txt.h new file mode 100644 index 0000000..94918e8 --- /dev/null +++ b/2024/day16/sample1.txt.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern uint32_t _binary_2024_day16_sample1_txt_start __asm("_binary_2024_day16_sample1_txt_start"); +extern uint32_t _binary_2024_day16_sample1_txt_end __asm("_binary_2024_day16_sample1_txt_end"); +extern uint32_t _binary_2024_day16_sample1_txt_size __asm("_binary_2024_day16_sample1_txt_size"); + +#ifdef __cplusplus +} +#endif diff --git a/2024/day16/solution.c b/2024/day16/solution.c new file mode 100644 index 0000000..baed3fe --- /dev/null +++ b/2024/day16/solution.c @@ -0,0 +1,109 @@ +#include + +#include +//#include "printf.h" +#include "dijkstra.h" +#include "memory.h" + +static void parse_sewh(const char * input, int length, + int * stride, + int * width, int * height, + int * start_x, int * start_y, + int * end_x, int * end_y + ) +{ + const char * end = input + length; + + *width = 0; + *height = 0; + + while (input < end) { + char c = *input++; + + switch (c) { + case 'S': + *start_x = *width; + *start_y = *height; + break; + case 'E': + *end_x = *width; + *end_y = *height; + break; + } + + *width += 1; + + if (c == '\n') { + *stride = *width; + *width = 0; + *height += 1; + continue; + } + } + + *width = *stride - 1; +} + +int64_t _2024_day16_part1(const char * input, int length) +{ + int stride; + int width; + int height; + int start_x; + int start_y; + int end_x; + int end_y; + + parse_sewh(input, length, + &stride, + &width, &height, + &start_x, &start_y, + &end_x, &end_y + ); + + struct dijkstra_xy16 prev[width * height]; + int dist[width * height]; + + dijkstra_cartesian(input, + stride, + width, height, + start_x, start_y, + end_x, end_y, + '#', + prev, + dist); + + char map[stride * height + 1]; + memory_copy_char(input, stride * height, map); + + int x = end_x; + int y = end_y; + while (!(x == start_x && y == start_y)) { + struct dijkstra_xy16 * xy = &prev[y * width + x]; + map[xy->y * stride + xy->x] = 'x'; + x = xy->x; + y = xy->y; + } + map[stride * height] = 0; + printf("%s", map); + + return dist[end_y * width + end_x]; +} + +int64_t _2024_day16_part2(const char * input, int length) +{ + return -1; +} + +#include + +int main() +{ + FILE * f = fopen("2024/day16/input.txt", "rb"); + const int length = 20022; + char buf[length]; + size_t len = fread(buf, 1, length, f); + assert(len == length); + fclose(f); + printf("%ld\n", _2024_day16_part1(buf, length)); +} diff --git a/aoc.mk b/aoc.mk index 07f2497..f469e21 100644 --- a/aoc.mk +++ b/aoc.mk @@ -8,7 +8,8 @@ OBJ = \ array.o \ memory.o \ heap.o \ - linear_algebra.o + linear_algebra.o \ + dijkstra.o DREAMCAST_OBJ = \ runner_dreamcast.o \ diff --git a/bfs.c b/bfs.c new file mode 100644 index 0000000..98fab55 --- /dev/null +++ b/bfs.c @@ -0,0 +1,75 @@ +#include + +#include "memory.h" +#include "cartesian.h" +#include "bfs.h" + +struct queue_descriptor { + int start; + int end; +}; + +struct position { + int16_t x; + int16_t y; +}; + +static inline void queue_append(struct position * queue, + struct queue_descriptor * qd, + int x, + int y) +{ + queue[qd->end].x = x; + queue[qd->end].y = y; + qd->end += 1; +} + +static inline struct position * queue_pop(struct position * queue, + struct queue_descriptor * qd) +{ + struct position * position = &queue[qd->start]; + qd->start += 1; + return position; +} + +void bfs(const char * graph, + int stride, + int width, int height, + int start_x, int start_y, + char wall, + struct cartesian_link * path) +{ + struct position queue[width * height]; + struct queue_descriptor qd; + qd.start = 0; + qd.end = 0; + + memory_set_int((int *)path, -1, width * height); + path[start_y * width + start_x].parent_x = start_x; + path[start_y * width + start_x].parent_y = start_y; + + queue_append(&queue, &qd, start_x, start_y); + + while (qd.start != qd.end) { + struct position * p = queue_pop(&queue, &qd); + + for (int i = 0; i < 4; i++) { + int nx = p->x + cartesian_neighbor[i].x; + int ny = p->y + cartesian_neighbor[i].y; + // ignore all edges that are outside the graph + if (!cartesian_inside(width, height, nx, ny)) + continue; + // ignore all edges that are walls + if (graph[ny * stride + nx] == wall) + continue; + // ignore all edges that were previously visited + if (path[ny * width + nx].parent_x != -1) + continue; + + path[ny * width + nx].parent_x = p->x; + path[ny * width + nx].parent_y = p->y; + + queue_append(&queue, &qd, nx, ny); + } + } +} diff --git a/bfs.h b/bfs.h new file mode 100644 index 0000000..c82ee15 --- /dev/null +++ b/bfs.h @@ -0,0 +1,23 @@ +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +void bfs(const char * graph, + int stride, + int width, int height, + int start_x, int start_y, + char wall, + struct cartesian_link * path); + +struct bfs_cartesian_link { + int16_t parent_x; + int16_t parent_y; +}; + +#ifdef __cplusplus +} +#endif diff --git a/dijkstra.c b/dijkstra.c new file mode 100644 index 0000000..5fa014f --- /dev/null +++ b/dijkstra.c @@ -0,0 +1,70 @@ +#include "cartesian.h" +#include "dijkstra.h" +#include "heap.h" +#include "memory.h" +//#include "printf.h" + +#include +#include + +void dijkstra_cartesian(const char * graph, + int stride, + int width, int height, + int start_x, int start_y, + int end_x, int end_y, + char wall, + struct dijkstra_xy16 * prev, + int * dist) +{ + struct heap_entry queue[width * height / 2 + 1]; + int queue_length = 0; + + // initialize all distances to the maximum distance + memory_set_int(dist, 0x7fffffff, width * height); + // initialize the distance from the start to the start to zero + dist[start_y * width + start_x] = 0; + + // initialize the all node paths to "unknown" + memory_set_int((int *)prev, -1, width * height); + prev[start_y * width + start_x] = + (struct dijkstra_xy16){start_x - 1, start_y}; // west + + // initialize the queue with "start" + heap_append_xy(queue, &queue_length, 0, start_x, start_y); + + while (queue_length > 0) { + struct heap_entry min = heap_extract_max(queue, &queue_length); + //if (min.x == end_x && min.y == end_y) + //return; + for (int i = 0; i < 4; i++) { + int nx = min.x + cartesian_neighbor[i].x; + int ny = min.y + cartesian_neighbor[i].y; + if (!cartesian_inside(width, height, nx, ny)) + continue; + if (graph[ny * stride + nx] == wall) + continue; + //if (prev[ny * width + nx].x != -1) + //continue; + int turn = 0; + struct dijkstra_xy16 * xy = &prev[min.y * width + min.x]; + int dx = min.x - xy->x; + int dy = min.y - xy->y; + if (min.y == 137) { + printf("xy % 2d % 2d pxy % 2d % 2d nxy % 2d % 2d dist %d\n", + min.x, min.y, + xy->x, xy->y, + nx, ny, + dist[min.y * width + min.x]); + } + if (cartesian_neighbor[i].x != dx || cartesian_neighbor[i].y != dy) + turn = 1000; + + int alt = dist[min.y * width + min.x] + 1 + turn; + if (alt < dist[ny * width + nx]) { + prev[ny * width + nx] = (struct dijkstra_xy16){min.x, min.y}; + dist[ny * width + nx] = alt; + heap_append_xy(queue, &queue_length, -alt, nx, ny); + } + } + } +} diff --git a/dijkstra.h b/dijkstra.h new file mode 100644 index 0000000..72035a3 --- /dev/null +++ b/dijkstra.h @@ -0,0 +1,25 @@ +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct dijkstra_xy16 { + int16_t x; + int16_t y; +}; + +void dijkstra_cartesian(const char * graph, + int stride, + int width, int height, + int start_x, int start_y, + int end_x, int end_y, + char wall, + struct dijkstra_xy16 * prev, + int * dist); + +#ifdef __cplusplus +} +#endif diff --git a/heap.c b/heap.c index f1214a7..a1c0225 100644 --- a/heap.c +++ b/heap.c @@ -1,4 +1,5 @@ #include "heap.h" +#include "memory.h" void heap_sift_up(struct heap_entry * e, int ix) { @@ -16,6 +17,31 @@ void heap_sift_up(struct heap_entry * e, int ix) } } +void heap_sift_down(struct heap_entry * e, int heap_length, int ix) +{ + while (true) { + int child_l = 2 * ix + 1; + int child_r = 2 * ix + 2; + if (child_l >= heap_length) + break; + + int child = child_l; + if (child_r < heap_length && e[child_l].key < e[child_r].key) { + child = child_r; + } + + if (e[ix].key < e[child].key) { + // swap child and ix + struct heap_entry tmp = e[child]; + e[child] = e[ix]; + e[ix] = tmp; + ix = child; + } else { + break; + } + } +} + void heap_append(struct heap_entry * e, int * heap_length, int key, int value) { int ix = *heap_length; @@ -25,6 +51,16 @@ void heap_append(struct heap_entry * e, int * heap_length, int key, int value) (*heap_length) += 1; } +void heap_append_xy(struct heap_entry * e, int * heap_length, int key, int x, int y) +{ + int ix = *heap_length; + e[ix].key = key; + e[ix].x = x; + e[ix].y = y; + heap_sift_up(e, ix); + (*heap_length) += 1; +} + int heap_find(struct heap_entry * e, int length, int ix, int key) { if (e[ix].key == key) @@ -47,3 +83,15 @@ int heap_find(struct heap_entry * e, int length, int ix, int key) return -1; } + +#define u32_per_heap_entry ((sizeof (struct heap_entry)) / (sizeof (uint32_t))) + +struct heap_entry heap_extract_max(struct heap_entry * e, int * heap_length) +{ + struct heap_entry entry = e[0]; + (*heap_length)--; + e[0] = e[*heap_length]; + heap_sift_down(e, *heap_length, 0); + + return entry; +} diff --git a/heap.h b/heap.h index 21fb15a..9a22772 100644 --- a/heap.h +++ b/heap.h @@ -1,17 +1,28 @@ #pragma once +#include + #ifdef __cplusplus extern "C" { #endif struct heap_entry { int key; - int value; + union { + int value; + struct { + int16_t x; + int16_t y; + }; + }; }; void heap_sift_up(struct heap_entry * e, int ix); +void heap_sift_down(struct heap_entry * e, int heap_length, int ix); void heap_append(struct heap_entry * e, int * heap_length, int key, int value); +void heap_append_xy(struct heap_entry * e, int * heap_length, int key, int x, int y); int heap_find(struct heap_entry * e, int length, int ix, int key); +struct heap_entry heap_extract_max(struct heap_entry * e, int * heap_length); #ifdef __cplusplus } diff --git a/input_dreamcast.inc b/input_dreamcast.inc index 17b93d4..509e45f 100644 --- a/input_dreamcast.inc +++ b/input_dreamcast.inc @@ -41,6 +41,8 @@ #include "2024/day14/input.txt.h" #include "2024/day15/sample1.txt.h" #include "2024/day15/input.txt.h" +#include "2024/day16/sample1.txt.h" +#include "2024/day16/input.txt.h" static struct start_size sample[][2] = { { @@ -163,6 +165,12 @@ static struct start_size sample[][2] = { { ( char *)&_binary_2024_day15_sample1_txt_start, (uint32_t)&_binary_2024_day15_sample1_txt_size }, }, + { + { ( char *)&_binary_2024_day16_sample1_txt_start, + (uint32_t)&_binary_2024_day16_sample1_txt_size }, + { ( char *)&_binary_2024_day16_sample1_txt_start, + (uint32_t)&_binary_2024_day16_sample1_txt_size }, + }, }; static struct start_size input[] = { @@ -206,4 +214,6 @@ static struct start_size input[] = { (uint32_t)&_binary_2024_day14_input_txt_size }, { ( char *)&_binary_2024_day15_input_txt_start, (uint32_t)&_binary_2024_day15_input_txt_size }, + { ( char *)&_binary_2024_day16_input_txt_start, + (uint32_t)&_binary_2024_day16_input_txt_size }, }; diff --git a/linear_algebra.c b/linear_algebra.c index dd9d258..27251f3 100644 --- a/linear_algebra.c +++ b/linear_algebra.c @@ -1,7 +1,6 @@ #include "linear_algebra.h" #include "printf.h" -//#include double determinant_2x2(double a, double b, double c, double d) @@ -14,32 +13,6 @@ double determinant_2x2(double a, double b, return a * d - b * c; } -/* -5550.00 450000000444000.00 600000000222000.00 -81081081161.08 108108108148.11 - --3876.00 -460000000548084.00 -400000000524792.00 -118679050709.00 103199174542.00 - --6595.00 -470000000250610.00 -690000000567170.00 -71266110727.92 104624715779.71 - -4278.00 440000001045978.00 460000000280508.00 -102851800151.00 107526881786.00 -*/ - -union di { - double d; - int64_t i; -}; - -static int64_t raw_double(double n) -{ - union di di; - di.d = n; - return di.i; -} - struct double2 cramers_rule_2x2(double a1, double b1, double c1, double a2, double b2, double c2) { diff --git a/memory.c b/memory.c index fc68db0..9de916b 100644 --- a/memory.c +++ b/memory.c @@ -16,9 +16,20 @@ void memory_set_int(int * buf, int c, int length) } } -void memory_copy_char(char * src, int length, char * dst) +void memory_copy_char(const char * src, int length, char * dst) { for (int i = 0; i < length; i += 1) { dst[i] = src[i]; } } + +void memory_copy_u32(const void * _src, int length, void * _dst) +{ + // size given in bytes + const uint32_t * src = _src; + uint32_t * dst = _dst; + + for (int i = 0; i < length; i++) { + dst[i] = src[i]; + } +} diff --git a/memory.h b/memory.h index f8c7995..24f0b11 100644 --- a/memory.h +++ b/memory.h @@ -6,7 +6,8 @@ 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); +void memory_copy_char(const char * src, int length, char * dst); +void memory_copy_u32(const void * _src, int length, void * _dst); #ifdef __cplusplus } diff --git a/runner.c b/runner.c index 4f889a3..32f8ed4 100644 --- a/runner.c +++ b/runner.c @@ -38,7 +38,7 @@ bool runner_tick(struct runner_state * runner_state) int year = solution[ix].year; int day = solution[ix].day; - if (year != 2024 || day != 15) { + if (year != 2024 || day != 16) { return false; } diff --git a/runner.inc b/runner.inc index a731291..3b5efcb 100644 --- a/runner.inc +++ b/runner.inc @@ -44,6 +44,8 @@ void _2024_day14_render(const struct font * font, 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); +int64_t _2024_day16_part1(const char * input, int length); +int64_t _2024_day16_part2(const char * input, int length); struct day_funcs solution[] = { { @@ -146,4 +148,9 @@ struct day_funcs solution[] = { {_2024_day15_part1, _2024_day15_part2}, NULL, }, + { + 2024, 16, + {_2024_day16_part1, _2024_day16_part2}, + NULL, + }, }; diff --git a/solutions.mk b/solutions.mk index 9217c94..8aac665 100644 --- a/solutions.mk +++ b/solutions.mk @@ -63,4 +63,7 @@ DAY_OBJ = \ 2024/day14/solution.o \ 2024/day15/sample1.txt.o \ 2024/day15/input.txt.o \ - 2024/day15/solution.o + 2024/day15/solution.o \ + 2024/day16/sample1.txt.o \ + 2024/day16/input.txt.o \ + 2024/day16/solution.o diff --git a/test/run.sh b/test/run.sh new file mode 100644 index 0000000..a7742b9 --- /dev/null +++ b/test/run.sh @@ -0,0 +1,20 @@ +#!bin/bash + +set -eux + +for i in test/test_heap.c; do + name=${i%.c} + gcc -Og -g -gdwarf-5 \ + -std=c2x \ + -Wall -Werror -Wfatal-errors \ + -Wno-error=unused-variable \ + -I. \ + -o ${name} \ + ${name}.c \ + memory.c \ + dijkstra.c \ + heap.c \ + cartesian.c + + ./${name} +done diff --git a/test/runner.h b/test/runner.h new file mode 100644 index 0000000..88630b1 --- /dev/null +++ b/test/runner.h @@ -0,0 +1,27 @@ +#pragma once + +typedef bool (*test_t)(const char ** scenario); + +#define ANSI_RED "\x1b[31m" +#define ANSI_GREEN "\x1b[32m" +#define ANSI_RESET "\x1b[0m" + +#define RUNNER(tests) \ + int main() \ + { \ + int fail_count = 0; \ + for (int i = 0; i < (sizeof (tests)) / (sizeof (test_t)); i++) { \ + const char * scenario = NULL; \ + bool result = tests[i](&scenario); \ + const char * result_s = result ? "ok" : ANSI_RED "fail" ANSI_RESET; \ + fail_count += !result; \ + fprintf(stderr, "%s: %s\n", scenario, result_s); \ + } \ + if (fail_count == 0) { \ + fprintf(stderr, ANSI_GREEN "failed tests: %d\n\n" ANSI_RESET, fail_count); \ + } else { \ + fprintf(stderr, ANSI_RED "failed tests: %d\n\n" ANSI_RESET, fail_count); \ + } \ + \ + return !(fail_count == 0); \ + } diff --git a/test/test_dijkstra.c b/test/test_dijkstra.c new file mode 100644 index 0000000..ee180f3 --- /dev/null +++ b/test/test_dijkstra.c @@ -0,0 +1,76 @@ +#include +#include + +#include "runner.h" + +#include "dijkstra.h" +#include "memory.h" + +static const char * graph = +"###############\n" +"#.......#....E#\n" +"#.#.###.#.###.#\n" +"#.....#.#...#.#\n" +"#.###.#####.#.#\n" +"#.#.#.......#.#\n" +"#.#.#####.###.#\n" +"#...........#.#\n" +"###.#.#####.#.#\n" +"#...#.....#.#.#\n" +"#.#.#.###.#.#.#\n" +"#.....#...#.#.#\n" +"#.###.#.#.#.#.#\n" +"#S..#.....#...#\n" +"###############\n" + ; + +static bool dijkstra_test_0(const char ** scenario) +{ + *scenario = "dijkstra"; + + int width = 15; + int height = 15; + int stride = 16; + int start_x = 1; + int start_y = 13; + int end_x = 13; + int end_y = 1; + + struct dijkstra_xy16 prev[width * height]; + int dist[width * height]; + + dijkstra_cartesian(graph, + stride, + width, height, + end_x, end_y, + start_x, start_y, + '#', + prev, + dist); + + char map[stride * height]; + memory_copy_char(graph, stride * height, map); + + int x = end_x; + int y = end_y; + int cost = 0; + while (!(x == start_x && y == start_y)) { + printf("%2d %2d %d\n", x, y, dist[y * width + x]); + struct dijkstra_xy16 xy = prev[y * width + x]; + map[xy.y * stride + xy.x] = 'x'; + x = xy.x; + y = xy.y; + } + printf("%2d %2d %d\n", x, y, dist[y * width + x]); + + printf("%d\n", cost); + puts(map); + + return true; +} + +test_t dijkstra_tests[] = { + dijkstra_test_0, +}; + +RUNNER(dijkstra_tests) diff --git a/test/test_heap.c b/test/test_heap.c new file mode 100644 index 0000000..43d88df --- /dev/null +++ b/test/test_heap.c @@ -0,0 +1,35 @@ +#include +#include + +#include "runner.h" + +#include "heap.h" + +static bool heap_test_0(const char ** scenario) +{ + *scenario = "heap_extract_max"; + + struct heap_entry e[100]; + int heap_length = 0; + int n[] = {-17, -57, -84, -88, -44, -77, -13, -80, -51, -37, -54, -74, -51, -74, -69, -15, -53, -74, -48, -93, -18, -14, -97, -35, -72, -73, -85, -42, -9, -53, -47, -93, -63, -81, -41, -48, -52, -67, -58, -24, -70, -4, -9, -67, -29, -54, -26, -35, -23, -96, -83, -68, -88, -73, -70, -71, -41, -78, -91, -96, -6, -33, -15, -56, -95, -62, -62, -88, -37, -96, -86, -53, -82, -84, -73, -25, -94, -1, -9, -80, -99, -35, -81, -51, -19, -64, -6, -88, -94, -30, -3, -88, -63, -43, -40, -86, -48, -66, -16, -21}; + for (int i = 0; i < 100; i++) { + heap_append(e, &heap_length, n[i], 0); + } + + int max = 999; + while (heap_length > 0) { + struct heap_entry ei = heap_extract_max(e, &heap_length); + printf("%d %d\n", ei.key, max); + if (ei.key > max) + return false; + max = ei.key; + } + + return true; +} + +test_t heap_tests[] = { + heap_test_0, +}; + +RUNNER(heap_tests) diff --git a/test/test_memory b/test/test_memory new file mode 100755 index 0000000000000000000000000000000000000000..4e74456f7a2556d71ef14c49f179296298db47b4 GIT binary patch literal 29616 zcmeHwd3@B>+3z{OZ6=u{6G$Kn+XTX@2}wXC8YF=PCKv@m&`^bGNG40oW-@`$vPr-) zZ;U`+tJtPsm$&t`_KLkO)YdkN0_|%pS{G{jY3X7OrM9@+TFw1FXPHa}Xy4Dh_pf_% z;CG($tmiq;dCr;NHj^D?70V3HnJy-~h7qBkwb+0Z_~qvP9G~*mULqw**b{ zizNV8mea;a=vH(Sko3~2aS=FCl9`6uLxQAtsdAniLeY?^agd%(428$S_guteOhe6& z^yd?7#$w<}<-dl}dgRKH9I1C?(MZ^+;<8ggtw$*74Jf?5oo%@VqGR%_7zgFl^6S?! zm>D3N3L`UiN?fHC))W_fZQoEhR74?N@|pN#j|$mR?g>b?h%e&6Z$pb2M5DQUA^3bt z;oH4>xe#we@c|nMhUv84cnF)V}miX}(q zDGLNTLp8Ox1Zo>^3Dnm#HG@#!-qF+=swWaK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H!ef@W&^V*?SE=!5gG!&%I`4H}$APAES176~uU +#include + +#include "runner.h" + +#include "memory.h" + +static bool memory_test_0(const char ** scenario) +{ + *scenario = "memory_copy_u32 ordering"; + + uint32_t l[] = {1, 2, 3, 4}; + + memory_copy_u32(&l[1], 3, &l[0]); + + return l[0] == 2 && l[1] == 3 && l[2] == 4; +} + +test_t memory_tests[] = { + memory_test_0, +}; + +RUNNER(memory_tests)