diff --git a/day/02/part2.sh b/day/02/part2.sh index 4786e7b..22ad5a6 100755 --- a/day/02/part2.sh +++ b/day/02/part2.sh @@ -59,7 +59,7 @@ while read -r l; do # start with the first val prev_val="${line_split[0]}" - is_safe=1 + is_safe=2 # if positive, going up, if negative, going down! is_up_down="$((line_split[1] - line_split[0]))" @@ -83,12 +83,11 @@ while read -r l; do if [[ "${test_is_safe}" -eq 0 ]]; then # normally we fail this set - is_safe=0 + is_safe=$((is_safe - 1)) fi if [[ "${test_is_safe}" -eq 0 ]] && [[ "${safety_trigger}" -eq 1 ]]; then # but we let 1 happen if the trigger hasnt... triggered - is_safe=1 safety_trigger=0 if [[ "${idx}" -eq 1 ]]; then # we may have to re-calculate is_up_down! @@ -104,13 +103,9 @@ while read -r l; do fi done - if [[ "${is_safe}" -eq 0 ]]; then - echo "final check unsafe" - else - echo "final check safe" + if [[ "${is_safe}" -gt 0 ]]; then + safe_count=$((safe_count + 1)) fi - echo "" - safe_count=$((safe_count + is_safe)) done <"$FILE_IN" echo "final safe count ${safe_count}"