Fixed missing paste. Working part 1

This commit is contained in:
2024-12-15 16:18:50 +08:00
parent 615f9ec252
commit 415f757054

View File

@ -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"