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
|
if [[ $line == *','* ]]; then
|
||||||
dots[$line]=1
|
dots[$line]=1
|
||||||
else
|
else
|
||||||
folds+=( $(sed 's/fold along //' <<< $line) )
|
folds+=( ${line#fold along } )
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
fold=${folds[0]}
|
fold=${folds[0]}
|
||||||
fold_axis=$(sed 's/=.*$//' <<< $fold)
|
fold_axis=${fold%=*}
|
||||||
fold_coord=$(sed 's/^.*=//' <<< $fold)
|
fold_coord=${fold#*=}
|
||||||
new_dots=()
|
new_dots=()
|
||||||
todel_dots=()
|
todel_dots=()
|
||||||
|
|
||||||
for dot in ${!dots[@]}; do
|
for dot in ${!dots[@]}; do
|
||||||
dot_x=$(sed 's/,.*$//' <<< $dot)
|
dot_x=${dot%,*}
|
||||||
dot_y=$(sed 's/^.*,//' <<< $dot)
|
dot_y=${dot#*,}
|
||||||
if [[ $fold_axis == 'x' ]]; then
|
if [[ $fold_axis == 'x' ]]; then
|
||||||
if [ $dot_x -gt $fold_coord ]; then
|
if [ $dot_x -gt $fold_coord ]; then
|
||||||
new_dots+=( "$((fold_coord*2-dot_x)),$dot_y" )
|
new_dots+=( "$((fold_coord*2-dot_x)),$dot_y" )
|
||||||
|
|||||||
10
13/02.sh
10
13/02.sh
@@ -9,13 +9,13 @@ while read line; do
|
|||||||
if [[ $line == *','* ]]; then
|
if [[ $line == *','* ]]; then
|
||||||
dots[$line]=1
|
dots[$line]=1
|
||||||
else
|
else
|
||||||
folds+=( $(sed 's/fold along //' <<< $line) )
|
folds+=( ${line#fold along } )
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
for fold in ${folds[@]}; do
|
for fold in ${folds[@]}; do
|
||||||
fold_axis=$(sed 's/=.*$//' <<< $fold)
|
fold_axis=${fold%=*}
|
||||||
fold_coord=$(sed 's/^.*=//' <<< $fold)
|
fold_coord=${fold#*=}
|
||||||
new_dots=()
|
new_dots=()
|
||||||
todel_dots=()
|
todel_dots=()
|
||||||
|
|
||||||
@@ -26,8 +26,8 @@ for fold in ${folds[@]}; do
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
for dot in ${!dots[@]}; do
|
for dot in ${!dots[@]}; do
|
||||||
dot_x=$(sed 's/,.*$//' <<< $dot)
|
dot_x=${dot%,*}
|
||||||
dot_y=$(sed 's/^.*,//' <<< $dot)
|
dot_y=${dot#*,}
|
||||||
if [[ $fold_axis == 'x' ]]; then
|
if [[ $fold_axis == 'x' ]]; then
|
||||||
if [ $dot_x -gt $fold_coord ]; then
|
if [ $dot_x -gt $fold_coord ]; then
|
||||||
new_dots+=( "$((fold_coord*2-dot_x)),$dot_y" )
|
new_dots+=( "$((fold_coord*2-dot_x)),$dot_y" )
|
||||||
|
|||||||
Reference in New Issue
Block a user