This commit is contained in:
2024-12-15 22:45:25 +08:00
parent 37667c0990
commit f6e91fa1fa

View File

@ -4,7 +4,6 @@ FUNCNEST=99999
MAP_FILE=input-map
DIRECTIONS_FILE=input-movements
MAP_WIDTH=$(( ( $( head -1 "$MAP_FILE" | wc -c ) -1 ) * 2 ))
MAP_HEIGHT=$( < "$MAP_FILE" wc -l )
# Move the robot
move_robot() {
@ -132,15 +131,6 @@ horizontal_move_box () {
}
# Load map
read -r -a TEST_ARRAY <<< "$(
< "$MAP_FILE" paste -s -d "" |
sed -E '
s/#/##/g;
s/\./../g;
s/@/@./g;
s/O/[]/g;
s/(.)(.)/\1 \2 /g'
)"
read -r -a MAP_ARRAY <<< "$(
< "$MAP_FILE" paste -s -d "" |
sed -E '
@ -158,17 +148,6 @@ print_map () {
printf "\n"
}
# Count boxes
#BOX_COUNT=0
#for (( i=0; i<MAP_LEN; i++ ))
#do
# if [[ ${MAP_ARRAY[$i]} == "[" ]]
# then
# (( BOX_COUNT++ ))
# fi
#done
#printf "Box count: %s\n" "$BOX_COUNT"
# Get robot position
for (( i=0; i<MAP_LEN; i++ ))
do
@ -260,31 +239,12 @@ do
if [[ ${MAP_ARRAY[i]} == "[" ]]
then
(( BOX_COUNT++ ))
#X_L=$(( i % MAP_WIDTH ))
#X_R=$(( MAP_WIDTH - (i % MAP_WIDTH ) -1 ))
#Y_T=$(( i / MAP_WIDTH * 100 ))
#Y_B=$(( ( MAP_HEIGHT - i / MAP_WIDTH ) * 100 ))
#X=$(( X_R > X_L ? X_L : X_R ))
#Y=$(( Y_T > Y_B ? Y_B : Y_T ))
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"
#if [[ $GPS -lt 0 ]] ; then printf "Negative GPS: %s for box %s\n" "$GPS" "$i"; continue; fi
(( 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<MAP_LEN; i++ ))
do
if [[ ${TEST_ARRAY[i]} == "#" ]]
then
if [[ ${TEST_ARRAY[i]} != "${MAP_ARRAY[i]}" ]]
then
printf "Index %s Wall changed.\n" "$i"
fi
fi
done