Day 13 faster without sed
This commit is contained in:
10
13/01.sh
10
13/01.sh
@@ -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" )
|
||||
|
||||
Reference in New Issue
Block a user