From adc6e0d0a715614184fd4840d929d24c8c717c69 Mon Sep 17 00:00:00 2001 From: "matthias@arch" Date: Fri, 8 Dec 2023 13:52:28 +0100 Subject: [PATCH] modify readme --- 01/README.md | 8 +++-- 02/README.md | 4 +-- 03/README.md | 1 + 04/README.md | 1 + 05/README.md | 6 ++-- 06/README.md | 4 +-- 07/README.md | 3 +- README.md | 18 +++++----- README.md.temp | 9 ++--- make_day_readme.sh | 89 ++++++++++++++++++++++++++++++++++++++++++++++ make_readme.sh | 30 ++-------------- 11 files changed, 123 insertions(+), 50 deletions(-) create mode 100755 make_day_readme.sh diff --git a/01/README.md b/01/README.md index 27a4975..5bf96e0 100644 --- a/01/README.md +++ b/01/README.md @@ -1,14 +1,16 @@ -# [Day 1](https://adventofcode.com/2022/day/1) +# [Day 1](https://adventofcode.com/2023/day/1) :gift: Today's language: **Python** +Execution time: **0,021 s** Both tasks are solved in one hell of a oneliner each: + - Task 1: 153 characters / line - Task 2: 363 characters / line - ```shell -p day01.py +python3 day01.py ``` + diff --git a/02/README.md b/02/README.md index 7654a03..3c0ab48 100644 --- a/02/README.md +++ b/02/README.md @@ -2,12 +2,12 @@ :gift::gift: Today's language: **Rust** +Execution time: **0,002 s** My very first rust program! - - ```shell rustc day02.rs ./day02 ``` + diff --git a/03/README.md b/03/README.md index 94e368c..ec1d043 100644 --- a/03/README.md +++ b/03/README.md @@ -2,6 +2,7 @@ :gift::gift::gift: Today's language: **Rust** +Execution time: **0,006 s** ```shell rustc day03.rs diff --git a/04/README.md b/04/README.md index 57ee78e..1e2abca 100644 --- a/04/README.md +++ b/04/README.md @@ -2,6 +2,7 @@ :gift::gift::gift::gift: Today's language: **Rust** +Execution time: **0,004 s** ```shell rustc day04.rs diff --git a/05/README.md b/05/README.md index 47e8779..84c3a74 100644 --- a/05/README.md +++ b/05/README.md @@ -2,12 +2,12 @@ :gift::gift::gift::gift::gift: Today's language: **Rust** +Execution time: **0,009 s** -Super fast, it runs both tasks in 0,002s on my pc. - - +Super fast! ```shell rustc day05.rs ./day05 ``` + diff --git a/06/README.md b/06/README.md index da582e0..e71fe83 100644 --- a/06/README.md +++ b/06/README.md @@ -2,12 +2,12 @@ :gift::gift::gift::gift::gift::gift: Today's language: **Rust** +Execution time: **0,001 s** *Midnight formula go brrrrr* - - ```shell rustc day06.rs ./day06 ``` + diff --git a/07/README.md b/07/README.md index e995e72..b1afc68 100644 --- a/07/README.md +++ b/07/README.md @@ -2,6 +2,7 @@ :gift::gift::gift::gift::gift::gift::gift: Today's language: **Rust** +Execution time: **0,007 s** Not pretty, but pretty fast. @@ -9,4 +10,4 @@ Not pretty, but pretty fast. rustc day07.rs ./day07 ``` - + diff --git a/README.md b/README.md index bca1fb2..91625f9 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,13 @@ This is a repository for my solutions for the [advent of code 2023](https://adventofcode.com/2023). -| Day | Language | Execuction time | Comment | -|:---: |:---: | ---: | --- | -| [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* | +| Day | Language | Execuction time | Comment | +|:---: |:---: | ---: | --- | +| [01](01) | Python | 0,021 s | one-liners | +| [02](02) | Rust | 0,002 s | my very first rust program | +| [03](03) | Rust | 0,006 s | | +| [04](04) | Rust | 0,004 s | | +| [05](05) | Rust | 0,009 s | very efficient | +| [06](06) | Rust | 0,001 s | quadratic formula go *brrr* | +| [07](07) | Rust | 0,007 s | not pretty, but pretty fast | +| [08](08) | Rust | 0,039 s | | diff --git a/README.md.temp b/README.md.temp index e0af62a..f4216b6 100644 --- a/README.md.temp +++ b/README.md.temp @@ -1,9 +1,10 @@ -# [Day X](https://adventofcode.com/2023/day/X) +# [Day DAY](https://adventofcode.com/2023/day/DAY) :gift: -Today's language: **Y** +Today's language: **LANG** +Execution time: **EXECTIME** ```shell - +HOWTORUN ``` - + diff --git a/make_day_readme.sh b/make_day_readme.sh new file mode 100755 index 0000000..70329ad --- /dev/null +++ b/make_day_readme.sh @@ -0,0 +1,89 @@ +#!/bin/bash +# pass comment as param $1 and select day with day=X ./make_day_readme.sh +maxday=$(ls -d */ | sed -r 's|0*(.*)/|\1|g' | tail -1) +[[ -z $day ]] && day=$maxday +day_dir=$(printf "%02d" $day) +readme=$day_dir/README.md + +FMT_VAR='\e[32m%s: \e[0m%s\n' +FMT_ERR='\e[31m%s\e[0m\n' +FMT_WARN='\e[33m%s\e[0m\n' + +echo Making Readme of day $day in $readme + +function find_lang { + # 1: fileext, 2: lang, 3: howto + sourcefile=$(ls $day_dir/*.$1 2> /dev/null) + [[ $? != 0 ]] && return + sourcefile=$(basename $sourcefile) + printf "$FMT_VAR" "Determined Langugae" "$2 ($sourcefile)" + sed -i "s/LANG/$2/" $readme + howto=$(echo "$3" | sed "s|SOURCE|$sourcefile|") + sed -i "s(HOWTORUN($howto(" $readme +} + +function get_time { + cd $day_dir + exe=$(find . -type f -executable) + exe=$(basename $exe) + if [[ $(echo $exe | wc -w) != 1 ]]; then + printf "$FMT_ERR" "Found multiple or no executables for day $day: '$exe'" + return 1 + time=Error + else + time=$({ time ./$exe; } 2>&1) + if [[ $? != 0 ]]; then + printf "$FMT_ERR" "Execution error in './$exe' in '$(pwd)'. Output:" + printf "\e[34m" + echo -e "$time" + printf "\e[0m" + return 1 + fi + time=$(echo -e "$time" | 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 +} + + + +gifts="" +for i in $(seq $day); do gifts+=":gift:"; done +sed "s/DAY/$day/g" README.md.temp | sed "s/:gift:/$gifts/" > $day_dir/README.md +get_time +if [[ $? == 0 ]]; then + cd .. + printf "$FMT_VAR" "exectime" "$time" + sed -i "s/EXECTIME/$time/" $readme +else + cd .. + printf "$FMT_WARN" "No execution time determined" + sed -i '/.*EXECTIME.*/d' $readme +fi + + + +if [[ -z $1 ]]; then + printf "$FMT_WARN" "No comment provided" + sed -i "//d" $readme +else + printf "$FMT_VAR" "Comment" "'$1'" + sed -i "s|COMMENT|$1|" $readme +fi + +find_lang py Python "python3 SOURCE" +find_lang rs Rust "rustc SOURCE\n./day${day_dir}" +find_lang cpp C++ "g++ SOURCE -o day${day_dir}\n ./day${day_dir}" diff --git a/make_readme.sh b/make_readme.sh index 96b79de..406470e 100755 --- a/make_readme.sh +++ b/make_readme.sh @@ -1,38 +1,14 @@ #!/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 + lang=$(grep -E "Today's language:" $day/README.md | sed -r 's/.*\*\*(.+)\*\*.*/\1/') + exectime=$(grep -E "Execution time:" $day/README.md | sed -r 's/.*\*\*(.+)\*\*.*/\1/') comment=$(grep -E "" $day/README.md | head -1 | sed -r 's/.*.*/\1/') - table+="| [$day]($day) | $lang | $time | $comment |\n" - + table+="| [$day]($day) | $lang | $exectime | $comment |\n" done # remove table from readme sed -i '//q' README.md