day 9 part 1 solution

This commit is contained in:
2024-12-09 17:17:34 +08:00
parent da0db2fde1
commit b4b2a6e794
4 changed files with 64 additions and 2 deletions

View File

@ -40,6 +40,7 @@ do
while true
do
HEAD=$(( A - DIFF * HEADC ))
if [[ ${SHADOW_ARRAY[HEAD]} == "X" ]]; then (( HEADC++ )); continue ; fi
HEADVDIFF=$(( (A / LEN) - (HEAD / LEN) ))
# Check if out of bounds
if [[ $HEAD -lt ${#MAP_ARRAY[@]} ]] && \
@ -57,6 +58,7 @@ do
while true
do
TAIL=$(( B + DIFF * TAILC ))
if [[ ${SHADOW_ARRAY[TAIL]} == "X" ]]; then (( TAILC++ )); continue ; fi
TAILVDIFF=$(( (TAIL / LEN) - (B / LEN) ))
# Check if out of bounds
if [[ $TAIL -lt ${#MAP_ARRAY[@]} ]] && \
@ -75,6 +77,6 @@ do
unset IDX_ARRAY
done
printf "%s" "${SHADOW_ARRAY[@]}" | fold -w "$LEN" | sed -E 's/(.)/\1\ /g'
printf "\n"
#printf "%s" "${SHADOW_ARRAY[@]}" | fold -w "$LEN" | sed -E 's/(.)/\1\ /g'
#printf "\n"
printf "%s" "${SHADOW_ARRAY[@]}" | grep -o 'X' | wc -l