From 6e0f9ca885fc32d6a84e52242c1e1593c7434412 Mon Sep 17 00:00:00 2001 From: Brett Parker Date: Tue, 8 Dec 2020 01:28:49 +0000 Subject: [PATCH] Add percentage done ticker --- day10/check_asteroids.sh | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/day10/check_asteroids.sh b/day10/check_asteroids.sh index 84958ed..e0bf959 100755 --- a/day10/check_asteroids.sh +++ b/day10/check_asteroids.sh @@ -96,7 +96,7 @@ check_collision() { cur_y=$((cur_y+$minstep_y)) debug_line "Step: $cur_x,$cur_y" if [ $cur_x -eq $vector1_x ] && [ $cur_y -eq $vector1_y ]; then - debug_line echo "Collision!" + debug_line "Collision!" return 0 fi done @@ -133,13 +133,17 @@ keep_going() { # we check for if the first asteroid is blocked viewing the second asteroid # by the third asteroid, if not we add 1 to it's total -for asteroid in ${!asteroids[@]}; do -#for asteroid in 9,0; do +asteroid_loop=("${!asteroids[@]}") +index=0 +start_count=${#asteroids[@]} +for asteroid in ${asteroid_loop[@]}; do ast1_x=${asteroid%,*} ast1_y=${asteroid#*,} - for asteroid2 in ${!asteroids[@]}; do - #for asteroid2 in 4,5; do + cur_count=${#asteroid_loop[@]} + percent=$((100-(100*$cur_count / $start_count))) + printf '\r%02d%% complete' $percent + for asteroid2 in ${asteroid_loop[@]}; do if [ $asteroid2 == $asteroid ]; then continue fi @@ -154,7 +158,7 @@ for asteroid in ${!asteroids[@]}; do fi if ! [ ${cansee[$asteroid,$asteroid2]+a} ]; then # we already calculated this backwards - for asteroid3 in ${!asteroids[@]}; do + for asteroid3 in "${!asteroids[@]}"; do if [ $asteroid == $asteroid3 ] || [ $asteroid2 == $asteroid3 ]; then continue fi @@ -173,10 +177,14 @@ for asteroid in ${!asteroids[@]}; do fi # nothing blocked the view of asteroid2 from asteroid1 debug_line "Apparently $asteroid can set $asteroid2" - asteroids[$asteroid]=$((asteroids[$asteroid]+1)) + asteroids[$asteroid]=$((${asteroids[$asteroid]}+1)) + asteroids[$asteroid2]=$((${asteroids[$asteroid2]}+1)) cansee[$asteroid2,$asteroid]=1 # don't bother doing the expensive calculations on the return path done + unset asteroid_loop[$index] + index=$((index+1)) done +echo -n $'\r'" "$'\r' best_ast= best_count=0 -- 2.39.5