Day 13 faster without sed

This commit is contained in:
2021-12-13 14:09:12 +01:00
parent 9a717cbe14
commit 6c2a3378a1
2 changed files with 10 additions and 10 deletions

View File

@@ -7,19 +7,19 @@ while read line; do
if [[ $line == *','* ]]; then
dots[$line]=1
else
folds+=( $(sed 's/fold along //' <<< $line) )
folds+=( ${line#fold along } )
fi
done
fold=${folds[0]}
fold_axis=$(sed 's/=.*$//' <<< $fold)
fold_coord=$(sed 's/^.*=//' <<< $fold)
fold_axis=${fold%=*}
fold_coord=${fold#*=}
new_dots=()
todel_dots=()
for dot in ${!dots[@]}; do
dot_x=$(sed 's/,.*$//' <<< $dot)
dot_y=$(sed 's/^.*,//' <<< $dot)
dot_x=${dot%,*}
dot_y=${dot#*,}
if [[ $fold_axis == 'x' ]]; then
if [ $dot_x -gt $fold_coord ]; then
new_dots+=( "$((fold_coord*2-dot_x)),$dot_y" )

View File

@@ -9,13 +9,13 @@ while read line; do
if [[ $line == *','* ]]; then
dots[$line]=1
else
folds+=( $(sed 's/fold along //' <<< $line) )
folds+=( ${line#fold along } )
fi
done
for fold in ${folds[@]}; do
fold_axis=$(sed 's/=.*$//' <<< $fold)
fold_coord=$(sed 's/^.*=//' <<< $fold)
fold_axis=${fold%=*}
fold_coord=${fold#*=}
new_dots=()
todel_dots=()
@@ -26,8 +26,8 @@ for fold in ${folds[@]}; do
fi
for dot in ${!dots[@]}; do
dot_x=$(sed 's/,.*$//' <<< $dot)
dot_y=$(sed 's/^.*,//' <<< $dot)
dot_x=${dot%,*}
dot_y=${dot#*,}
if [[ $fold_axis == 'x' ]]; then
if [ $dot_x -gt $fold_coord ]; then
new_dots+=( "$((fold_coord*2-dot_x)),$dot_y" )