1 mapfile
-t list
< <(sed 's/turn //; s/through //; s/,/ /g')
2 echo "parsed ${#list[*]} instructions"
4 for row
in {0.
.999}; do
5 echo "processing row $row"
6 for col in {0.
.999}; do
10 for ((i
= 0; i
< ${#list[*]}; i
++)); do
11 # printf '\b\b\b%3d' $i
12 read inst x1 y1 x2 y2
<<< ${list[$i]}
13 if [[ $row -lt $y1 ||
$row -gt $y2 ]]; then
14 # echo " no-op for inst $i on row $row"
17 # echo " $i: running operation $inst over $((x2-x1+1)) cells"
19 while [[ $pos -le $x2 ]]; do
24 toggle
) line
[$pos]=$
((1-${line[$pos]})) ;;
25 *) echo oops
; exit 2 ;;
29 on
) line
[$pos]=$
((${line[$pos]}+1)) ;;
30 off
) line
[$pos]=$
((${line[$pos]}?
${line[$pos]}-1:0)) ;;
31 toggle
) line
[$pos]=$
((${line[$pos]}+2)) ;;
32 *) echo oops
; exit 2 ;;
38 subcount
=$
(( $
(echo ${line[*]} |
tr ' ' +) ))
40 printf "row $row adds $subcount\n"
41 count
=$
((count
+ subcount
))
43 echo "final count $count"