modify readme
This commit is contained in:
parent
ead01162cb
commit
adc6e0d0a7
@ -1,14 +1,16 @@
|
|||||||
# [Day 1](https://adventofcode.com/2022/day/1)
|
# [Day 1](https://adventofcode.com/2023/day/1)
|
||||||
:gift:
|
:gift:
|
||||||
|
|
||||||
Today's language: **Python**
|
Today's language: **Python**
|
||||||
|
Execution time: **0,021 s**
|
||||||
|
|
||||||
Both tasks are solved in one hell of a oneliner each:
|
Both tasks are solved in one hell of a oneliner each:
|
||||||
|
|
||||||
- Task 1: 153 characters / line
|
- Task 1: 153 characters / line
|
||||||
- Task 2: 363 characters / line
|
- Task 2: 363 characters / line
|
||||||
|
|
||||||
<!-- one-liners -->
|
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
p day01.py
|
python3 day01.py
|
||||||
```
|
```
|
||||||
|
<!-- one-liners -->
|
||||||
|
@ -2,12 +2,12 @@
|
|||||||
:gift::gift:
|
:gift::gift:
|
||||||
|
|
||||||
Today's language: **Rust**
|
Today's language: **Rust**
|
||||||
|
Execution time: **0,002 s**
|
||||||
|
|
||||||
My very first rust program!
|
My very first rust program!
|
||||||
|
|
||||||
<!-- my very first rust program -->
|
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
rustc day02.rs
|
rustc day02.rs
|
||||||
./day02
|
./day02
|
||||||
```
|
```
|
||||||
|
<!-- my very first rust program -->
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
:gift::gift::gift:
|
:gift::gift::gift:
|
||||||
|
|
||||||
Today's language: **Rust**
|
Today's language: **Rust**
|
||||||
|
Execution time: **0,006 s**
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
rustc day03.rs
|
rustc day03.rs
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
:gift::gift::gift::gift:
|
:gift::gift::gift::gift:
|
||||||
|
|
||||||
Today's language: **Rust**
|
Today's language: **Rust**
|
||||||
|
Execution time: **0,004 s**
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
rustc day04.rs
|
rustc day04.rs
|
||||||
|
@ -2,12 +2,12 @@
|
|||||||
:gift::gift::gift::gift::gift:
|
:gift::gift::gift::gift::gift:
|
||||||
|
|
||||||
Today's language: **Rust**
|
Today's language: **Rust**
|
||||||
|
Execution time: **0,009 s**
|
||||||
|
|
||||||
Super fast, it runs both tasks in 0,002s on my pc.
|
Super fast!
|
||||||
|
|
||||||
<!-- very efficient -->
|
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
rustc day05.rs
|
rustc day05.rs
|
||||||
./day05
|
./day05
|
||||||
```
|
```
|
||||||
|
<!-- very efficient -->
|
||||||
|
@ -2,12 +2,12 @@
|
|||||||
:gift::gift::gift::gift::gift::gift:
|
:gift::gift::gift::gift::gift::gift:
|
||||||
|
|
||||||
Today's language: **Rust**
|
Today's language: **Rust**
|
||||||
|
Execution time: **0,001 s**
|
||||||
|
|
||||||
*Midnight formula go brrrrr*
|
*Midnight formula go brrrrr*
|
||||||
|
|
||||||
<!-- quadratic formula go *brrrr* -->
|
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
rustc day06.rs
|
rustc day06.rs
|
||||||
./day06
|
./day06
|
||||||
```
|
```
|
||||||
|
<!-- quadratic formula go *brrr* -->
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
:gift::gift::gift::gift::gift::gift::gift:
|
:gift::gift::gift::gift::gift::gift::gift:
|
||||||
|
|
||||||
Today's language: **Rust**
|
Today's language: **Rust**
|
||||||
|
Execution time: **0,007 s**
|
||||||
|
|
||||||
Not pretty, but pretty fast.
|
Not pretty, but pretty fast.
|
||||||
|
|
||||||
@ -9,4 +10,4 @@ Not pretty, but pretty fast.
|
|||||||
rustc day07.rs
|
rustc day07.rs
|
||||||
./day07
|
./day07
|
||||||
```
|
```
|
||||||
<!-- -->
|
<!-- not pretty, but pretty fast -->
|
||||||
|
18
README.md
18
README.md
@ -2,11 +2,13 @@
|
|||||||
This is a repository for my solutions for the [advent of code 2023](https://adventofcode.com/2023).
|
This is a repository for my solutions for the [advent of code 2023](https://adventofcode.com/2023).
|
||||||
|
|
||||||
<!-- table begin -->
|
<!-- table begin -->
|
||||||
| Day | Language | Execuction time | Comment |
|
| Day | Language | Execuction time | Comment |
|
||||||
|:---: |:---: | ---: | --- |
|
|:---: |:---: | ---: | --- |
|
||||||
| [01](01) | Python | 0,015 s | one-liners |
|
| [01](01) | Python | 0,021 s | one-liners |
|
||||||
| [02](02) | Rust | 0,001 s | my very first rust program |
|
| [02](02) | Rust | 0,002 s | my very first rust program |
|
||||||
| [03](03) | Rust | 0,001 s | |
|
| [03](03) | Rust | 0,006 s | |
|
||||||
| [04](04) | Rust | 0,001 s | |
|
| [04](04) | Rust | 0,004 s | |
|
||||||
| [05](05) | Rust | 0,001 s | very efficient |
|
| [05](05) | Rust | 0,009 s | very efficient |
|
||||||
| [06](06) | Rust | 0,001 s | quadratic formula go *brrrr* |
|
| [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 | |
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
# [Day X](https://adventofcode.com/2023/day/X)
|
# [Day DAY](https://adventofcode.com/2023/day/DAY)
|
||||||
:gift:
|
:gift:
|
||||||
|
|
||||||
Today's language: **Y**
|
Today's language: **LANG**
|
||||||
|
Execution time: **EXECTIME**
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
|
HOWTORUN
|
||||||
```
|
```
|
||||||
<!-- -->
|
<!-- COMMENT -->
|
||||||
|
89
make_day_readme.sh
Executable file
89
make_day_readme.sh
Executable file
@ -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 "/<!-- COMMENT -->/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}"
|
@ -1,38 +1,14 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
table="| Day | Language | Execuction time | Comment |\n"
|
table="| Day | Language | Execuction time | Comment |\n"
|
||||||
table+="|:---:|:---:| ---:| --- |\n"
|
table+="|:---:|:---:| ---:| --- |\n"
|
||||||
for day in $(seq -f "%02g" 1 25); do
|
for day in $(seq -f "%02g" 1 25); do
|
||||||
[[ ! -d "$day" ]] && continue
|
[[ ! -d "$day" ]] && continue
|
||||||
# echo $day
|
# echo $day
|
||||||
lang=$(grep -E "Today's language: "'\*\*[a-zA-Z0-9_]+\*\*' $day/README.md | sed -r 's/.*\*\*(.+)\*\*.*/\1/')
|
lang=$(grep -E "Today's language:" $day/README.md | sed -r 's/.*\*\*(.+)\*\*.*/\1/')
|
||||||
exe=$(find $day -type f -executable)
|
exectime=$(grep -E "Execution time:" $day/README.md | sed -r 's/.*\*\*(.+)\*\*.*/\1/')
|
||||||
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/')
|
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
|
done
|
||||||
# remove table from readme
|
# remove table from readme
|
||||||
sed -i '/<!-- table begin -->/q' README.md
|
sed -i '/<!-- table begin -->/q' README.md
|
||||||
|
Loading…
Reference in New Issue
Block a user