From 415f7570541b784a124651aebd800eafdd81d84f Mon Sep 17 00:00:00 2001 From: Clement Date: Sun, 15 Dec 2024 16:18:50 +0800 Subject: [PATCH] Fixed missing paste. Working part 1 --- 2024/day-15/solution-1.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/2024/day-15/solution-1.sh b/2024/day-15/solution-1.sh index 44ad24c..a14a036 100644 --- a/2024/day-15/solution-1.sh +++ b/2024/day-15/solution-1.sh @@ -41,6 +41,7 @@ LEFT=-1 RIGHT=1 # Iterate through directions +MOVES=0 while read -r DIRECTION do @@ -71,7 +72,7 @@ do if [[ ${MAP_ARRAY[$END_POSITION]} == '#' ]] then 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 + : # 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]}" @@ -86,7 +87,7 @@ do 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]}" @@ -95,8 +96,10 @@ do ROBOT_POSITION=$NEXT_POSITION MAP_ARRAY[ROBOT_POSITION]=@ fi + (( MOVES++ )) -done <<< "$( < "$DIRECTIONS_FILE" sed -E 's/(.)(.)/\1 \2 /g' | tr ' ' '\n' )" +done <<< "$( < "$DIRECTIONS_FILE" paste -s -d "" | sed -E 's/(.)(.)/\1 \2 /g' | tr ' ' '\n' )" +printf "Moves: %s\n" "$MOVES" printf "%s " "${MAP_ARRAY[@]}" | fold -w $(( MAP_WIDTH * 2 )) printf "\n"