From ef47dd932ba59ad1c12d249587a3e59ae5e279f1 Mon Sep 17 00:00:00 2001 From: "matthias@arch" Date: Wed, 6 Dec 2023 12:15:51 +0100 Subject: [PATCH] add scripts and readme template --- .gitignore | 5 ++++- README.md | 12 ++++++------ README.md.temp | 9 +++++++++ make_readme.sh | 39 +++++++++++++++++++++++++++++++++++++++ next_day.sh | 9 +++++++++ 5 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 README.md.temp create mode 100755 make_readme.sh create mode 100755 next_day.sh diff --git a/.gitignore b/.gitignore index c9fa88e..bc9104e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ -README.md.temp +# ignore all without extension +* +!*.* +!*/ *.txt diff --git a/README.md b/README.md index 0060053..ddc99dd 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ This is a repository for my solutions for the [advent of code 2023](https://adve | Day | Language | Execuction time | Comment | | --- |:---: | ---: | --- | -| [01](01) | Python | 0m0,015s | one-liners | -| [02](02) | Rust | 0m0,001s | My very first rust program | -| [03](03) | Rust | 0m0,001s | | -| [04](04) | Rust | 0m0,001s | | -| [05](05) | Rust | 0m0,001s | very efficient | -| [06](06) | Rust | 0m0,001s | quadratic formula go *brrrr* | +| [01](01) | Python | 0,015 s | one-liners | +| [02](02) | Rust | 0,001 s | My very first rust program | +| [03](03) | Rust | 0,001 s | | +| [04](04) | Rust | 0,001 s | | +| [05](05) | Rust | 0,001 s | very efficient | +| [06](06) | Rust | 0,001 s | quadratic formula go *brrrr* | diff --git a/README.md.temp b/README.md.temp new file mode 100644 index 0000000..e0af62a --- /dev/null +++ b/README.md.temp @@ -0,0 +1,9 @@ +# [Day X](https://adventofcode.com/2023/day/X) +:gift: + +Today's language: **Y** + +```shell + +``` + diff --git a/make_readme.sh b/make_readme.sh new file mode 100755 index 0000000..99fbdff --- /dev/null +++ b/make_readme.sh @@ -0,0 +1,39 @@ +#!/bin/bash + + + +table="| Day | Language | Execuction time | Comment |\n" +table+="| --- |:---:| ---:| --- |\n" +for day in $(seq -f "%02g" 1 25); do + [[ ! -d "$day" ]] && continue + # echo $day + lang=$(grep -E "Today's language: "'\*\*[a-zA-Z0-9_]+\*\*' $day/README.md | sed -r 's/.*\*\*(.+)\*\*.*/\1/') + exe=$(find $day -type f -executable) + if [[ $(echo $exe | wc -w) != 1 ]]; then + echo "Found multiple or no executables for day $day: '$exe'" + time=Error + else + time=$({ time ./$exe; } 2>&1 | tail -3 | head -1 | awk '{print $2}') + re='([[:digit:]]+)m([[:digit:]]+),([[:digit:]]+)s' + [[ $time =~ $re ]] + min=${BASH_REMATCH[1]} + sec=${BASH_REMATCH[2]} + msec=${BASH_REMATCH[3]} + if [[ $min != 0 ]]; then + time="$min m $sec,$msec s" + else + time="$sec,$msec s" + fi + # elif [[ $sec != 0 ]]; then + # time="$sec,$msec s" + # else + # time="$((msec+0)) ms" + # fi + fi + comment=$(grep -E "" $day/README.md | head -1 | sed -r 's/.*.*/\1/') + table+="| [$day]($day) | $lang | $time | $comment |\n" + +done +# remove table from readme +sed -i '//q' README.md +echo -e $table | column -t -s '|' -o '|' >> README.md diff --git a/next_day.sh b/next_day.sh new file mode 100755 index 0000000..5955eec --- /dev/null +++ b/next_day.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +maxday=$(ls -d */ | sed -r 's|0*(.*)/|\1|g' | tail -1) +echo $maxday +nextday=$((maxday + 1)) +nextday_dir=$(printf "%02d" $nextday) +echo $nextday +mkdir $nextday_dir +sed "s/X/$nextday/g" README.md.temp > $nextday_dir/README.md