diff --git a/CMakeLists.txt b/CMakeLists.txt index 29e0301..ab16be3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,10 +17,11 @@ file(GLOB SRC2020 src/2020/*.c) file(GLOB SRC2021 src/2021/*.c) file(GLOB SRC2022 src/2022/*.c) file(GLOB SRC2023 src/2023/*.c) +file(GLOB SRC2024 src/2024/*.c) file(COPY input DESTINATION ${CMAKE_BINARY_DIR}) -add_executable(advent ${SRC} ${SRC2015} ${SRC2016} ${SRC2017} ${SRC2018} ${SRC2019} ${SRC2020} ${SRC2021} ${SRC2022} ${SRC2023}) +add_executable(advent ${SRC} ${SRC2015} ${SRC2016} ${SRC2017} ${SRC2018} ${SRC2019} ${SRC2020} ${SRC2021} ${SRC2022} ${SRC2023} ${SRC2024}) if ((${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD")) target_link_libraries(advent PRIVATE flint) diff --git a/README.md b/README.md index 3312cbd..933246b 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Advent Of Code solutions using C99. Builds and runs on macOS, Linux, and OpenBSD Be sure to clone the project with its submodules: - git clone --recurse-submodules https://git.burkey.co/eburk/advent + git clone --recurse-submodules https://gitlab.com/eburk/aoc This project relies on several BSD extensions to the stdlib. OpenBSD and macOS users should be able to build the project out of the box. Linux users will need `libbsd` installed. The package is called `libbsd-dev` on Debian-based systems. diff --git a/generator.sh b/generator.sh index ffc3828..9b3ef5d 100755 --- a/generator.sh +++ b/generator.sh @@ -2,7 +2,7 @@ mkdir -p include -for year in {2023..2023}; do +for year in {2015..2024}; do rm -rf "src/${year}" mkdir -p "src/${year}" diff --git a/get_input.sh b/get_input.sh index 8dae29f..3d2acce 100755 --- a/get_input.sh +++ b/get_input.sh @@ -4,8 +4,21 @@ get(){ curl -s --cookie "session=$1" "$2" | perl -pe 'chomp if eof' > "$3" } -rm -rf input -for year in {2015..2023}; do +if [ -n "${2+x}" ] && [ -n "${3+x}" ]; then + year="20$2" + day="$3" + if [ "$day" -lt 10 ]; then + d="0$day" + else + d="$day" + fi + url="https://adventofcode.com/$year/day/$day/input" + get "$1" "$url" "input/$year/$d" + exit 0 +fi + +#rm -rf input +for year in {2015..2024}; do mkdir -p input/"$year" for day in {1..25}; do if [[ day -lt 10 ]]; then diff --git a/include/advent2024.h b/include/advent2024.h new file mode 100644 index 0000000..0176166 --- /dev/null +++ b/include/advent2024.h @@ -0,0 +1,58 @@ +#ifndef ADVENT_2024_H +#define ADVENT_2024_H + +void advent2024day01(void); +void advent2024day02(void); +void advent2024day03(void); +void advent2024day04(void); +void advent2024day05(void); +void advent2024day06(void); +void advent2024day07(void); +void advent2024day08(void); +void advent2024day09(void); +void advent2024day10(void); +void advent2024day11(void); +void advent2024day12(void); +void advent2024day13(void); +void advent2024day14(void); +void advent2024day15(void); +void advent2024day16(void); +void advent2024day17(void); +void advent2024day18(void); +void advent2024day19(void); +void advent2024day20(void); +void advent2024day21(void); +void advent2024day22(void); +void advent2024day23(void); +void advent2024day24(void); +void advent2024day25(void); + +void (*solutions2024[25])(void) = { + advent2024day01, + advent2024day02, + advent2024day03, + advent2024day04, + advent2024day05, + advent2024day06, + advent2024day07, + advent2024day08, + advent2024day09, + advent2024day10, + advent2024day11, + advent2024day12, + advent2024day13, + advent2024day14, + advent2024day15, + advent2024day16, + advent2024day17, + advent2024day18, + advent2024day19, + advent2024day20, + advent2024day21, + advent2024day22, + advent2024day23, + advent2024day24, + advent2024day25 +}; + +#endif diff --git a/src/2015/05.c b/src/2015/05.c index 79bea2a..1827af3 100644 --- a/src/2015/05.c +++ b/src/2015/05.c @@ -1,13 +1,13 @@ #include #include -#include "advent_utility.h" +#include void advent2015day05(void) { /* Sometimes, grep really is the best tool */ - char *p1 = capture_system( - "grep -E \"(.*[aeiou]){3}\" ./input/2015/05 | grep \"\\(.\\)\\1\" | egrep -v \"(ab|cd|pq|xy)\" | wc -l"); - char *p2 = capture_system("grep \"\\(..\\).*\\1\" ./input/2015/05 | grep \"\\(.\\).\\1\" | wc -l"); + const char *p1 = capture_system( + "grep -E \"(.*[aeiou]){3}\" ./input/2015/05 | grep \"\\(.\\)\\1\" | egrep -v \"(ab|cd|pq|xy)\" | wc -l", 0); + const char *p2 = capture_system("grep \"\\(..\\).*\\1\" ./input/2015/05 | grep \"\\(.\\).\\1\" | wc -l", 0); printf("%s%s", p1, p2); diff --git a/src/2024/01.c b/src/2024/01.c new file mode 100644 index 0000000..d72bdf8 --- /dev/null +++ b/src/2024/01.c @@ -0,0 +1,10 @@ +#include +#include + +#include "lfinput.h" + +void advent2024day01(void) { + char *input = get_input("input/2024/01"); + printf("Solution for Day 01 of 2024 is not completed yet\n"); + free(input); +} diff --git a/src/2024/02.c b/src/2024/02.c new file mode 100644 index 0000000..0014c6c --- /dev/null +++ b/src/2024/02.c @@ -0,0 +1,10 @@ +#include +#include + +#include "lfinput.h" + +void advent2024day02(void) { + char *input = get_input("input/2024/02"); + printf("Solution for Day 02 of 2024 is not completed yet\n"); + free(input); +} diff --git a/src/2024/03.c b/src/2024/03.c new file mode 100644 index 0000000..354e9f1 --- /dev/null +++ b/src/2024/03.c @@ -0,0 +1,10 @@ +#include +#include + +#include "lfinput.h" + +void advent2024day03(void) { + char *input = get_input("input/2024/03"); + printf("Solution for Day 03 of 2024 is not completed yet\n"); + free(input); +} diff --git a/src/2024/04.c b/src/2024/04.c new file mode 100644 index 0000000..e93100d --- /dev/null +++ b/src/2024/04.c @@ -0,0 +1,10 @@ +#include +#include + +#include "lfinput.h" + +void advent2024day04(void) { + char *input = get_input("input/2024/04"); + printf("Solution for Day 04 of 2024 is not completed yet\n"); + free(input); +} diff --git a/src/2024/05.c b/src/2024/05.c new file mode 100644 index 0000000..0403db6 --- /dev/null +++ b/src/2024/05.c @@ -0,0 +1,10 @@ +#include +#include + +#include "lfinput.h" + +void advent2024day05(void) { + char *input = get_input("input/2024/05"); + printf("Solution for Day 05 of 2024 is not completed yet\n"); + free(input); +} diff --git a/src/2024/06.c b/src/2024/06.c new file mode 100644 index 0000000..b209adc --- /dev/null +++ b/src/2024/06.c @@ -0,0 +1,10 @@ +#include +#include + +#include "lfinput.h" + +void advent2024day06(void) { + char *input = get_input("input/2024/06"); + printf("Solution for Day 06 of 2024 is not completed yet\n"); + free(input); +} diff --git a/src/2024/07.c b/src/2024/07.c new file mode 100644 index 0000000..e86d68f --- /dev/null +++ b/src/2024/07.c @@ -0,0 +1,10 @@ +#include +#include + +#include "lfinput.h" + +void advent2024day07(void) { + char *input = get_input("input/2024/07"); + printf("Solution for Day 07 of 2024 is not completed yet\n"); + free(input); +} diff --git a/src/2024/08.c b/src/2024/08.c new file mode 100644 index 0000000..3084b74 --- /dev/null +++ b/src/2024/08.c @@ -0,0 +1,10 @@ +#include +#include + +#include "lfinput.h" + +void advent2024day08(void) { + char *input = get_input("input/2024/08"); + printf("Solution for Day 08 of 2024 is not completed yet\n"); + free(input); +} diff --git a/src/2024/09.c b/src/2024/09.c new file mode 100644 index 0000000..98c9c9e --- /dev/null +++ b/src/2024/09.c @@ -0,0 +1,10 @@ +#include +#include + +#include "lfinput.h" + +void advent2024day09(void) { + char *input = get_input("input/2024/09"); + printf("Solution for Day 09 of 2024 is not completed yet\n"); + free(input); +} diff --git a/src/2024/10.c b/src/2024/10.c new file mode 100644 index 0000000..148c1f3 --- /dev/null +++ b/src/2024/10.c @@ -0,0 +1,10 @@ +#include +#include + +#include "lfinput.h" + +void advent2024day10(void) { + char *input = get_input("input/2024/10"); + printf("Solution for Day 10 of 2024 is not completed yet\n"); + free(input); +} diff --git a/src/2024/11.c b/src/2024/11.c new file mode 100644 index 0000000..1c3aa6b --- /dev/null +++ b/src/2024/11.c @@ -0,0 +1,10 @@ +#include +#include + +#include "lfinput.h" + +void advent2024day11(void) { + char *input = get_input("input/2024/11"); + printf("Solution for Day 11 of 2024 is not completed yet\n"); + free(input); +} diff --git a/src/2024/12.c b/src/2024/12.c new file mode 100644 index 0000000..f887052 --- /dev/null +++ b/src/2024/12.c @@ -0,0 +1,10 @@ +#include +#include + +#include "lfinput.h" + +void advent2024day12(void) { + char *input = get_input("input/2024/12"); + printf("Solution for Day 12 of 2024 is not completed yet\n"); + free(input); +} diff --git a/src/2024/13.c b/src/2024/13.c new file mode 100644 index 0000000..3ee6622 --- /dev/null +++ b/src/2024/13.c @@ -0,0 +1,10 @@ +#include +#include + +#include "lfinput.h" + +void advent2024day13(void) { + char *input = get_input("input/2024/13"); + printf("Solution for Day 13 of 2024 is not completed yet\n"); + free(input); +} diff --git a/src/2024/14.c b/src/2024/14.c new file mode 100644 index 0000000..3331432 --- /dev/null +++ b/src/2024/14.c @@ -0,0 +1,10 @@ +#include +#include + +#include "lfinput.h" + +void advent2024day14(void) { + char *input = get_input("input/2024/14"); + printf("Solution for Day 14 of 2024 is not completed yet\n"); + free(input); +} diff --git a/src/2024/15.c b/src/2024/15.c new file mode 100644 index 0000000..3f78bb7 --- /dev/null +++ b/src/2024/15.c @@ -0,0 +1,10 @@ +#include +#include + +#include "lfinput.h" + +void advent2024day15(void) { + char *input = get_input("input/2024/15"); + printf("Solution for Day 15 of 2024 is not completed yet\n"); + free(input); +} diff --git a/src/2024/16.c b/src/2024/16.c new file mode 100644 index 0000000..200c761 --- /dev/null +++ b/src/2024/16.c @@ -0,0 +1,10 @@ +#include +#include + +#include "lfinput.h" + +void advent2024day16(void) { + char *input = get_input("input/2024/16"); + printf("Solution for Day 16 of 2024 is not completed yet\n"); + free(input); +} diff --git a/src/2024/17.c b/src/2024/17.c new file mode 100644 index 0000000..ad8078f --- /dev/null +++ b/src/2024/17.c @@ -0,0 +1,10 @@ +#include +#include + +#include "lfinput.h" + +void advent2024day17(void) { + char *input = get_input("input/2024/17"); + printf("Solution for Day 17 of 2024 is not completed yet\n"); + free(input); +} diff --git a/src/2024/18.c b/src/2024/18.c new file mode 100644 index 0000000..37e11bf --- /dev/null +++ b/src/2024/18.c @@ -0,0 +1,10 @@ +#include +#include + +#include "lfinput.h" + +void advent2024day18(void) { + char *input = get_input("input/2024/18"); + printf("Solution for Day 18 of 2024 is not completed yet\n"); + free(input); +} diff --git a/src/2024/19.c b/src/2024/19.c new file mode 100644 index 0000000..d5fb099 --- /dev/null +++ b/src/2024/19.c @@ -0,0 +1,10 @@ +#include +#include + +#include "lfinput.h" + +void advent2024day19(void) { + char *input = get_input("input/2024/19"); + printf("Solution for Day 19 of 2024 is not completed yet\n"); + free(input); +} diff --git a/src/2024/20.c b/src/2024/20.c new file mode 100644 index 0000000..11c0365 --- /dev/null +++ b/src/2024/20.c @@ -0,0 +1,10 @@ +#include +#include + +#include "lfinput.h" + +void advent2024day20(void) { + char *input = get_input("input/2024/20"); + printf("Solution for Day 20 of 2024 is not completed yet\n"); + free(input); +} diff --git a/src/2024/21.c b/src/2024/21.c new file mode 100644 index 0000000..4c04bb5 --- /dev/null +++ b/src/2024/21.c @@ -0,0 +1,10 @@ +#include +#include + +#include "lfinput.h" + +void advent2024day21(void) { + char *input = get_input("input/2024/21"); + printf("Solution for Day 21 of 2024 is not completed yet\n"); + free(input); +} diff --git a/src/2024/22.c b/src/2024/22.c new file mode 100644 index 0000000..bf00ead --- /dev/null +++ b/src/2024/22.c @@ -0,0 +1,10 @@ +#include +#include + +#include "lfinput.h" + +void advent2024day22(void) { + char *input = get_input("input/2024/22"); + printf("Solution for Day 22 of 2024 is not completed yet\n"); + free(input); +} diff --git a/src/2024/23.c b/src/2024/23.c new file mode 100644 index 0000000..ece84f9 --- /dev/null +++ b/src/2024/23.c @@ -0,0 +1,10 @@ +#include +#include + +#include "lfinput.h" + +void advent2024day23(void) { + char *input = get_input("input/2024/23"); + printf("Solution for Day 23 of 2024 is not completed yet\n"); + free(input); +} diff --git a/src/2024/24.c b/src/2024/24.c new file mode 100644 index 0000000..aa0a4bf --- /dev/null +++ b/src/2024/24.c @@ -0,0 +1,10 @@ +#include +#include + +#include "lfinput.h" + +void advent2024day24(void) { + char *input = get_input("input/2024/24"); + printf("Solution for Day 24 of 2024 is not completed yet\n"); + free(input); +} diff --git a/src/2024/25.c b/src/2024/25.c new file mode 100644 index 0000000..502ad0b --- /dev/null +++ b/src/2024/25.c @@ -0,0 +1,10 @@ +#include +#include + +#include "lfinput.h" + +void advent2024day25(void) { + char *input = get_input("input/2024/25"); + printf("Solution for Day 25 of 2024 is not completed yet\n"); + free(input); +} diff --git a/src/main.c b/src/main.c index b23b8f8..f35d338 100644 --- a/src/main.c +++ b/src/main.c @@ -16,6 +16,7 @@ #include "advent2021.h" #include "advent2022.h" #include "advent2023.h" +#include "advent2024.h" int main(int argc, char **argv) { if (argc != 3) { @@ -27,7 +28,7 @@ int main(int argc, char **argv) { char buf[32]; const char *errstr = NULL; - year = strtonum(argv[1], 15, 23, &errstr); + year = strtonum(argv[1], 15, 24, &errstr); if (NULL != errstr) { printf("Input error: %s\n\n", errstr); return 1; @@ -67,6 +68,9 @@ int main(int argc, char **argv) { case 23: solutions2023[day - 1](); break; + case 24: + solutions2024[day - 1](); + break; } return 0;