Add generate_days script

- Add generate_days script to generate templated files for an advent of
  code year.
- Optimize the fetch.sh script (remove awk usage)
This commit is contained in:
Thraix
2026-07-25 19:57:11 +02:00
parent 6a3a1c9dc1
commit a9ac1c2c98
5 changed files with 59 additions and 8 deletions
+1
View File
@@ -8,3 +8,4 @@ bin/
cookies.txt cookies.txt
res/*/*/input.txt res/*/*/input.txt
Makefile Makefile
compile_flags.txt
+31
View File
@@ -0,0 +1,31 @@
#include "common/aoc.h"
namespace y$1::day$2
{
REGISTER_DAY($1, Day$2, std::vector<int>, int);
REGISTER_TEST_EXAMPLE($1, Day$2, ExampleInput, 1, 0);
REGISTER_TEST($1, Day$2, Input, 1, 0);
REGISTER_TEST_EXAMPLE($1, Day$2, ExampleInput, 2, 0);
REGISTER_TEST($1, Day$2, Input, 2, 0);
READ_INPUT(input)
{
std::vector<int> vec;
std::string str;
while (getline(input, str))
{
}
return vec;
}
OUTPUT1(input)
{
return 0;
}
OUTPUT2(input)
{
return 0;
}
}
-4
View File
@@ -1,4 +0,0 @@
-xc++
-Isrc/
-std=c++17
+4 -4
View File
@@ -1,4 +1,4 @@
#/bin/sh #!/bin/sh
if [ ! -e cookies.txt ]; then if [ ! -e cookies.txt ]; then
echo "No cookies.txt file exists" echo "No cookies.txt file exists"
@@ -8,11 +8,11 @@ fi
list=$(find -name "Day*.cpp" | awk -F '/' '{print $3 "/" $4}' | awk -F '.' '{print $1}' | sed 's/Day//g' | sort) list=$(find -name "Day*.cpp" | awk -F '/' '{print $3 "/" $4}' | awk -F '.' '{print $1}' | sed 's/Day//g' | sort)
for item in $list; do for item in $list; do
year=$(echo $item | awk -F '/' '{print $1}') year=${item%/*} # remove everything before /
day=$(echo $item | awk -F '/' '{print $2}') day=${item#*/} # remove everything after /
dir="res/$year/day$day/input.txt" dir="res/$year/day$day/input.txt"
if [ ! -e $dir ]; then if [ ! -e $dir ]; then
webitem=$(echo $day | sed 's/^0//g') webitem=${day#0}
echo "Fetching $dir" echo "Fetching $dir"
tmp_file=$(mktemp) tmp_file=$(mktemp)
HTTP_CODE=$(curl -s -w "%{http_code}" -o "$tmp_file" --cookie cookies.txt https://adventofcode.com/$year/day/$webitem/input) HTTP_CODE=$(curl -s -w "%{http_code}" -o "$tmp_file" --cookie cookies.txt https://adventofcode.com/$year/day/$webitem/input)
+23
View File
@@ -0,0 +1,23 @@
#!/bin/sh
leading_zero() {
printf '%02d\n' $1
}
if [ $# -le 1 ]; then
echo "year and amount of days arguments not passed"
exit 1
fi
mkdir 'src/'$1
mkdir 'res/'$1
for i in $(seq 1 $2); do
i2=$(leading_zero $i)
cat Template.cpp |
sed 's/$1/'$1'/g' |
sed 's/$2/'$i2'/g' > \
'src/'$1'/Day'$i2'.cpp'
res_dir='res/'$1'/day'$i2'/'
mkdir $res_dir
touch $res_dir'/test_input.txt'
done