diff --git a/13/01.sh b/13/01.sh index 3b2ffc7..cc29c56 100755 --- a/13/01.sh +++ b/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" ) diff --git a/13/02.sh b/13/02.sh index 0538b35..45e0678 100755 --- a/13/02.sh +++ b/13/02.sh @@ -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" )