X-Git-Url: https://git.sommitrealweird.co.uk/advent-of-code-2019.git/blobdiff_plain/8d19ec771c083ce8bbfff9b075d42f15ad704831..762c474265f967e401c9dfd52efdf81b2eeed9f0:/day10/check_asteroids.sh 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