From 615f9ec252d26d81f110f23f600c0554a1f3619c Mon Sep 17 00:00:00 2001 From: Clement Date: Sun, 15 Dec 2024 16:14:11 +0800 Subject: [PATCH] Added more wall tests. Made more verbose GPS counting. --- 2024/day-15/solution-1.sh | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/2024/day-15/solution-1.sh b/2024/day-15/solution-1.sh index 0036098..44ad24c 100644 --- a/2024/day-15/solution-1.sh +++ b/2024/day-15/solution-1.sh @@ -6,6 +6,7 @@ MAP_WIDTH=$(( $( head -1 "$MAP_FILE" | wc -c ) -1 )) #MAP_HEIGHT=$( < "$MAP_FILE" wc -l ) # Load map +read -r -a TEST_ARRAY <<< "$( < "$MAP_FILE" paste -s -d "" | sed -E 's/(.)(.)/\1 \2 /g' )" read -r -a MAP_ARRAY <<< "$( < "$MAP_FILE" paste -s -d "" | sed -E 's/(.)(.)/\1 \2 /g' )" printf "%s " "${MAP_ARRAY[@]}" | fold -w $(( MAP_WIDTH * 2 )) printf "\n" @@ -69,9 +70,11 @@ do done if [[ ${MAP_ARRAY[$END_POSITION]} == '#' ]] then - : # Boxes are stacked up against wall + printf "Next: %s End: %s Stacked boxes. No change.\n" "${MAP_ARRAY[$NEXT_POSITION]}" "${MAP_ARRAY[$END_POSITION]}" + continue # Boxes are stacked up against wall elif [[ ${MAP_ARRAY[$END_POSITION]} == "." ]] then + printf "Next: %s End: %s Robot: %s Move boxes and robot\n" "${MAP_ARRAY[$NEXT_POSITION]}" "${MAP_ARRAY[$END_POSITION]}" "${MAP_ARRAY[$ROBOT_POSITION]}" # Move the box MAP_ARRAY[END_POSITION]=O MAP_ARRAY[NEXT_POSITION]=. @@ -82,9 +85,11 @@ do fi elif [[ ${MAP_ARRAY[$NEXT_POSITION]} == "#" ]] # Wall in front, do nothing then + printf "Next: %s Skipping\n" "${MAP_ARRAY[$NEXT_POSITION]}" continue elif [[ ${MAP_ARRAY[$NEXT_POSITION]} == "." ]] # Empty space, move forward then + printf "Next: %s Move robot forward\n" "${MAP_ARRAY[$NEXT_POSITION]}" # Move the robot MAP_ARRAY[ROBOT_POSITION]=. ROBOT_POSITION=$NEXT_POSITION @@ -104,9 +109,24 @@ do if [[ ${MAP_ARRAY[i]} == "O" ]] then (( BOX_COUNT++ )) - (( SUM+=( (i / MAP_WIDTH) * 100 ) )) # Add Y axis - (( SUM+=( i % MAP_WIDTH ) )) # Add x axis + X=$(( i % MAP_WIDTH )) + Y=$(( i / MAP_WIDTH * 100 )) + GPS=$(( X + Y )) + printf "Box %s X: %s Y: %s GPS: %s\n" "$i" "$X" "$Y" "$GPS" + (( SUM+=GPS )) fi done printf "Sum: %s\n" "$SUM" printf "Box count: %s\n" "$BOX_COUNT" + +# Compare and test if walls have moved +for (( i=0; i