setup 2021, remove loop from main
This commit is contained in:
parent
cf470251b0
commit
0dfbe6c183
@ -14,10 +14,11 @@ file(GLOB SRC2017 src/2017/*.c)
|
||||
file(GLOB SRC2018 src/2018/*.c)
|
||||
file(GLOB SRC2019 src/2019/*.c)
|
||||
file(GLOB SRC2020 src/2020/*.c)
|
||||
file(GLOB SRC2021 src/2021/*.c)
|
||||
|
||||
file(COPY input DESTINATION ${CMAKE_BINARY_DIR})
|
||||
|
||||
add_executable(advent ${SRC} ${SRC2015} ${SRC2016} ${SRC2017} ${SRC2018} ${SRC2019} ${SRC2020})
|
||||
add_executable(advent ${SRC} ${SRC2015} ${SRC2016} ${SRC2017} ${SRC2018} ${SRC2019} ${SRC2020} ${SRC2021})
|
||||
|
||||
if ((${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD"))
|
||||
target_link_libraries(advent PRIVATE flint)
|
||||
|
@ -24,3 +24,11 @@ The supplied `build.sh` script does the above for you.
|
||||
Inputs can be generated from `get_input.sh`. You will need to get your session cookie from the Advent of Code website. The easiest way to do this is to inspect any input page in your browser.
|
||||
|
||||
The script can then be run with `bash get_input.sh SESSIONCOOKIE`, with `SESSIONCOOKIE` replaced by your unique session cookie's hash.
|
||||
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
./advent $YEAR $DAY
|
||||
```
|
||||
|
||||
For example, `./advent 15 1` will run Day 01 from the 2015 problems
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
mkdir -p include
|
||||
|
||||
for year in {2015..2020}; do
|
||||
for year in {2015..2021}; do
|
||||
rm -rf "src/${year}"
|
||||
mkdir -p "src/${year}"
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
rm -rf input
|
||||
for year in {2015..2020}; do
|
||||
for year in {2015..2021}; do
|
||||
mkdir -p input/$year
|
||||
for day in {1..25}; do
|
||||
if [[ day -lt 10 ]]; then
|
||||
|
58
include/advent2021.h
Normal file
58
include/advent2021.h
Normal file
@ -0,0 +1,58 @@
|
||||
#ifndef ADVENT_2021_H
|
||||
#define ADVENT_2021_H
|
||||
|
||||
void advent2021day01(void);
|
||||
void advent2021day02(void);
|
||||
void advent2021day03(void);
|
||||
void advent2021day04(void);
|
||||
void advent2021day05(void);
|
||||
void advent2021day06(void);
|
||||
void advent2021day07(void);
|
||||
void advent2021day08(void);
|
||||
void advent2021day09(void);
|
||||
void advent2021day10(void);
|
||||
void advent2021day11(void);
|
||||
void advent2021day12(void);
|
||||
void advent2021day13(void);
|
||||
void advent2021day14(void);
|
||||
void advent2021day15(void);
|
||||
void advent2021day16(void);
|
||||
void advent2021day17(void);
|
||||
void advent2021day18(void);
|
||||
void advent2021day19(void);
|
||||
void advent2021day20(void);
|
||||
void advent2021day21(void);
|
||||
void advent2021day22(void);
|
||||
void advent2021day23(void);
|
||||
void advent2021day24(void);
|
||||
void advent2021day25(void);
|
||||
|
||||
void (*solutions2021[25])(void) = {
|
||||
advent2021day01,
|
||||
advent2021day02,
|
||||
advent2021day03,
|
||||
advent2021day04,
|
||||
advent2021day05,
|
||||
advent2021day06,
|
||||
advent2021day07,
|
||||
advent2021day08,
|
||||
advent2021day09,
|
||||
advent2021day10,
|
||||
advent2021day11,
|
||||
advent2021day12,
|
||||
advent2021day13,
|
||||
advent2021day14,
|
||||
advent2021day15,
|
||||
advent2021day16,
|
||||
advent2021day17,
|
||||
advent2021day18,
|
||||
advent2021day19,
|
||||
advent2021day20,
|
||||
advent2021day21,
|
||||
advent2021day22,
|
||||
advent2021day23,
|
||||
advent2021day24,
|
||||
advent2021day25
|
||||
};
|
||||
|
||||
#endif
|
10
src/2021/01.c
Normal file
10
src/2021/01.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "input.h"
|
||||
|
||||
void advent2021day01(void) {
|
||||
char *input = get_input("input/2021/01");
|
||||
printf("Solution for Day 01 of 2021 is not completed yet\n");
|
||||
free(input);
|
||||
}
|
10
src/2021/02.c
Normal file
10
src/2021/02.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "input.h"
|
||||
|
||||
void advent2021day02(void) {
|
||||
char *input = get_input("input/2021/02");
|
||||
printf("Solution for Day 02 of 2021 is not completed yet\n");
|
||||
free(input);
|
||||
}
|
10
src/2021/03.c
Normal file
10
src/2021/03.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "input.h"
|
||||
|
||||
void advent2021day03(void) {
|
||||
char *input = get_input("input/2021/03");
|
||||
printf("Solution for Day 03 of 2021 is not completed yet\n");
|
||||
free(input);
|
||||
}
|
10
src/2021/04.c
Normal file
10
src/2021/04.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "input.h"
|
||||
|
||||
void advent2021day04(void) {
|
||||
char *input = get_input("input/2021/04");
|
||||
printf("Solution for Day 04 of 2021 is not completed yet\n");
|
||||
free(input);
|
||||
}
|
10
src/2021/05.c
Normal file
10
src/2021/05.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "input.h"
|
||||
|
||||
void advent2021day05(void) {
|
||||
char *input = get_input("input/2021/05");
|
||||
printf("Solution for Day 05 of 2021 is not completed yet\n");
|
||||
free(input);
|
||||
}
|
10
src/2021/06.c
Normal file
10
src/2021/06.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "input.h"
|
||||
|
||||
void advent2021day06(void) {
|
||||
char *input = get_input("input/2021/06");
|
||||
printf("Solution for Day 06 of 2021 is not completed yet\n");
|
||||
free(input);
|
||||
}
|
10
src/2021/07.c
Normal file
10
src/2021/07.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "input.h"
|
||||
|
||||
void advent2021day07(void) {
|
||||
char *input = get_input("input/2021/07");
|
||||
printf("Solution for Day 07 of 2021 is not completed yet\n");
|
||||
free(input);
|
||||
}
|
10
src/2021/08.c
Normal file
10
src/2021/08.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "input.h"
|
||||
|
||||
void advent2021day08(void) {
|
||||
char *input = get_input("input/2021/08");
|
||||
printf("Solution for Day 08 of 2021 is not completed yet\n");
|
||||
free(input);
|
||||
}
|
10
src/2021/09.c
Normal file
10
src/2021/09.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "input.h"
|
||||
|
||||
void advent2021day09(void) {
|
||||
char *input = get_input("input/2021/09");
|
||||
printf("Solution for Day 09 of 2021 is not completed yet\n");
|
||||
free(input);
|
||||
}
|
10
src/2021/10.c
Normal file
10
src/2021/10.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "input.h"
|
||||
|
||||
void advent2021day10(void) {
|
||||
char *input = get_input("input/2021/10");
|
||||
printf("Solution for Day 10 of 2021 is not completed yet\n");
|
||||
free(input);
|
||||
}
|
10
src/2021/11.c
Normal file
10
src/2021/11.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "input.h"
|
||||
|
||||
void advent2021day11(void) {
|
||||
char *input = get_input("input/2021/11");
|
||||
printf("Solution for Day 11 of 2021 is not completed yet\n");
|
||||
free(input);
|
||||
}
|
10
src/2021/12.c
Normal file
10
src/2021/12.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "input.h"
|
||||
|
||||
void advent2021day12(void) {
|
||||
char *input = get_input("input/2021/12");
|
||||
printf("Solution for Day 12 of 2021 is not completed yet\n");
|
||||
free(input);
|
||||
}
|
10
src/2021/13.c
Normal file
10
src/2021/13.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "input.h"
|
||||
|
||||
void advent2021day13(void) {
|
||||
char *input = get_input("input/2021/13");
|
||||
printf("Solution for Day 13 of 2021 is not completed yet\n");
|
||||
free(input);
|
||||
}
|
10
src/2021/14.c
Normal file
10
src/2021/14.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "input.h"
|
||||
|
||||
void advent2021day14(void) {
|
||||
char *input = get_input("input/2021/14");
|
||||
printf("Solution for Day 14 of 2021 is not completed yet\n");
|
||||
free(input);
|
||||
}
|
10
src/2021/15.c
Normal file
10
src/2021/15.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "input.h"
|
||||
|
||||
void advent2021day15(void) {
|
||||
char *input = get_input("input/2021/15");
|
||||
printf("Solution for Day 15 of 2021 is not completed yet\n");
|
||||
free(input);
|
||||
}
|
10
src/2021/16.c
Normal file
10
src/2021/16.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "input.h"
|
||||
|
||||
void advent2021day16(void) {
|
||||
char *input = get_input("input/2021/16");
|
||||
printf("Solution for Day 16 of 2021 is not completed yet\n");
|
||||
free(input);
|
||||
}
|
10
src/2021/17.c
Normal file
10
src/2021/17.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "input.h"
|
||||
|
||||
void advent2021day17(void) {
|
||||
char *input = get_input("input/2021/17");
|
||||
printf("Solution for Day 17 of 2021 is not completed yet\n");
|
||||
free(input);
|
||||
}
|
10
src/2021/18.c
Normal file
10
src/2021/18.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "input.h"
|
||||
|
||||
void advent2021day18(void) {
|
||||
char *input = get_input("input/2021/18");
|
||||
printf("Solution for Day 18 of 2021 is not completed yet\n");
|
||||
free(input);
|
||||
}
|
10
src/2021/19.c
Normal file
10
src/2021/19.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "input.h"
|
||||
|
||||
void advent2021day19(void) {
|
||||
char *input = get_input("input/2021/19");
|
||||
printf("Solution for Day 19 of 2021 is not completed yet\n");
|
||||
free(input);
|
||||
}
|
10
src/2021/20.c
Normal file
10
src/2021/20.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "input.h"
|
||||
|
||||
void advent2021day20(void) {
|
||||
char *input = get_input("input/2021/20");
|
||||
printf("Solution for Day 20 of 2021 is not completed yet\n");
|
||||
free(input);
|
||||
}
|
10
src/2021/21.c
Normal file
10
src/2021/21.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "input.h"
|
||||
|
||||
void advent2021day21(void) {
|
||||
char *input = get_input("input/2021/21");
|
||||
printf("Solution for Day 21 of 2021 is not completed yet\n");
|
||||
free(input);
|
||||
}
|
10
src/2021/22.c
Normal file
10
src/2021/22.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "input.h"
|
||||
|
||||
void advent2021day22(void) {
|
||||
char *input = get_input("input/2021/22");
|
||||
printf("Solution for Day 22 of 2021 is not completed yet\n");
|
||||
free(input);
|
||||
}
|
10
src/2021/23.c
Normal file
10
src/2021/23.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "input.h"
|
||||
|
||||
void advent2021day23(void) {
|
||||
char *input = get_input("input/2021/23");
|
||||
printf("Solution for Day 23 of 2021 is not completed yet\n");
|
||||
free(input);
|
||||
}
|
10
src/2021/24.c
Normal file
10
src/2021/24.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "input.h"
|
||||
|
||||
void advent2021day24(void) {
|
||||
char *input = get_input("input/2021/24");
|
||||
printf("Solution for Day 24 of 2021 is not completed yet\n");
|
||||
free(input);
|
||||
}
|
10
src/2021/25.c
Normal file
10
src/2021/25.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "input.h"
|
||||
|
||||
void advent2021day25(void) {
|
||||
char *input = get_input("input/2021/25");
|
||||
printf("Solution for Day 25 of 2021 is not completed yet\n");
|
||||
free(input);
|
||||
}
|
68
src/main.c
68
src/main.c
@ -12,52 +12,38 @@
|
||||
#include "advent2018.h"
|
||||
#include "advent2019.h"
|
||||
#include "advent2020.h"
|
||||
#include "advent2021.h"
|
||||
|
||||
int main(void) {
|
||||
int day, year;
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 3) {
|
||||
printf("Usage: advent $YEAR $DAY\nExample: advent 15 1 will run Solution Day 01 of 2015\n\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int day = 0, year = 0;
|
||||
char buf[32];
|
||||
const char *errstr;
|
||||
const char *errstr = NULL;
|
||||
|
||||
printf("--- Advent of Code ---\n");
|
||||
year = strtonum(argv[1], 15, 21, &errstr);
|
||||
if (NULL != errstr) {
|
||||
printf("Input error: %s\n\n", errstr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
day = 0;
|
||||
year = 0;
|
||||
errstr = NULL;
|
||||
day = strtonum(argv[2], 1, 25, &errstr);
|
||||
if (NULL != errstr) {
|
||||
printf("Input error: %s\n\n", errstr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Enter a year (15-20). Enter 'q' to quit: ");
|
||||
scanf("%s", buf);
|
||||
|
||||
if (0 == strcmp(buf, "Q") || 0 == strcmp(buf, "q")) {
|
||||
break;
|
||||
}
|
||||
|
||||
year = strtonum(buf, 15, 20, &errstr);
|
||||
if (NULL != errstr) {
|
||||
printf("Input error: %s\n\n", errstr);
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("Enter a day (1-25): ");
|
||||
scanf("%s", buf);
|
||||
day = strtonum(buf, 1, 25, &errstr);
|
||||
if (NULL != errstr) {
|
||||
printf("Input error: %s\n\n", errstr);
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
switch(year) {
|
||||
case 15: solutions2015[day-1](); break;
|
||||
case 16: solutions2016[day-1](); break;
|
||||
case 17: solutions2017[day-1](); break;
|
||||
case 18: solutions2018[day-1](); break;
|
||||
case 19: solutions2019[day-1](); break;
|
||||
case 20: solutions2020[day-1](); break;
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
switch(year) {
|
||||
case 15: solutions2015[day-1](); break;
|
||||
case 16: solutions2016[day-1](); break;
|
||||
case 17: solutions2017[day-1](); break;
|
||||
case 18: solutions2018[day-1](); break;
|
||||
case 19: solutions2019[day-1](); break;
|
||||
case 20: solutions2020[day-1](); break;
|
||||
case 21: solutions2021[day-1](); break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user