@@ -11,41 +11,30 @@ while read -r action x y _ X Y; do
11
11
AA[i]=${AA[i]: 0: x}${one: x: X-x+1}${AA[i]: X+1} ; done ;;
12
12
off) for i in " ${idx[@]: y: Y-y+1} " ; do
13
13
AA[i]=${AA[i]: 0: x}${zero: x: X-x+1}${AA[i]: X+1} ; done ;;
14
- toggle) PART=" " ;
14
+ toggle) PART=" "
15
15
for i in " ${idx[@]: y: Y-y+1} " ; do PART+=" ${AA[i]: x: X-x+1} " ; done
16
16
TMP=($( tr ' 01' ' 10' <<< " $PART" ) )
17
- for i in " ${idx[@]: y: Y-y+1} " ; do AA[i]=${AA[i]: 0: x}${TMP[i-y]}${AA[i]: X+1} ; done ;;
17
+ for i in " ${idx[@]: y: Y-y+1} " ; do
18
+ AA[i]=${AA[i]: 0: x}${TMP[i-y]}${AA[i]: X+1} ; done ;;
18
19
esac
19
20
done < <( sed " s/turn.//" " $input " )
20
- IFS= ' ' ANS= ${AA[* ]// 0}
21
+ printf -v ANS " %s " " ${AA[@ ]// 0} "
21
22
echo " 6A: ${# ANS} "
22
23
23
- if [[ -n ${2:- $PUREBASH } ]]; then
24
- IFS=$' ,\n '
25
- AA=($( printf " %.s$zero \n" " ${idx[@]} " ) )
26
- while read -r action x y _ X Y; do
27
- PART=" "
28
- for i in " ${idx[@]: y: $Y -y+1} " ; do PART+=" ${AA[i]: x: X-x+1} " ; done
29
- case $action in
30
- on) TMP=($( tr ' 0-9a-zA-Z' ' 1-9a-zA-Z?' <<< " $PART" ) );; # shift up by 1. '?' means overflow
31
- off) TMP=($( tr ' 1-9a-zA-Z' ' 0-9a-zA-Y' <<< " $PART" ) );; # shift down by 1
32
- toggle) TMP=($( tr ' 0-9a-zA-Z' ' 2-9a-zA-Z??' <<< " $PART" ) );; # shift up by 2
33
- esac
34
- for i in " ${idx[@]: y: Y-y+1} " ; do AA[i]=${AA[i]: 0: x}${TMP[i-y]}${AA[i]: X+1} ; done
35
- done < <( sed " s/turn.//" " $input " )
36
- # ANS=$(printf "%s" "${AA[@]//0}" | grep -o . | sort | uniq -c | sed "s/^ */+/;s/ /*/")
37
- ANS=$( printf " %s" " ${AA[@]// 0} " | sed " s/./+&/g" )
38
- XX=({0..9} {a..z} {A..Z})
39
- # convert a-z and A-Z to variables so that $((ANS)) converts a=10, z=35, A=36, etc
40
- for ii in " ${idx[@]: 10: 52} " ; do printf -v " ${XX[ii]} " " %s" " $ii " ; done
41
- echo " 6B: $(( ANS)) "
42
- else
43
- sed " s/turn.on/1/;s/turn.off/-1/;s/toggle/2/" " $input " | awk -F" [, ]" ' {
44
- for(y=$3;y<=$6;y++){ for(x=$2;x<=$5;x++){ if($1>0||A[y][x]>0){ A[y][x]+=$1 }}}
45
- }
46
- END {
47
- sum=0; for(y=0;y<=999;y++){ for(x=0;x<=999;x++) { sum+=A[y][x] }}
48
- print "6B(awk):", sum
49
- }
50
- '
51
- fi
24
+ AA=($( printf " %.s$zero \n" " ${idx[@]} " ) )
25
+ while read -r action x y _ X Y; do
26
+ PART=" "
27
+ for i in " ${idx[@]: y: $Y -y+1} " ; do PART+=" ${AA[i]: x: X-x+1} " ; done
28
+ case $action in
29
+ on) TMP=($( tr ' 0-9a-zA-Z' ' 1-9a-zA-Z?' <<< " $PART" ) );; # shift up by 1. '?' means overflow
30
+ off) TMP=($( tr ' 1-9a-zA-Z' ' 0-9a-zA-Y' <<< " $PART" ) );; # shift down by 1
31
+ toggle) TMP=($( tr ' 0-9a-zA-Z' ' 2-9a-zA-Z??' <<< " $PART" ) );; # shift up by 2
32
+ esac
33
+ for i in " ${idx[@]: y: Y-y+1} " ; do AA[i]=${AA[i]: 0: x}${TMP[i-y]}${AA[i]: X+1} ; done
34
+ done < <( sed " s/turn.//" " $input " )
35
+ # ANS=$(printf "%s" "${AA[@]//0}" | grep -o . | sort | uniq -c | sed "s/^ */+/;s/ /*/")
36
+ ANS=$( printf " %s" " ${AA[@]// 0} " | sed " s/./+&/g" )
37
+ XX=({0..9} {a..z} {A..Z})
38
+ # convert a-z and A-Z to variables so that $((ANS)) converts a=10, z=35, A=36, etc
39
+ for ii in " ${idx[@]: 10: 52} " ; do printf -v " ${XX[ii]} " " %s" " $ii " ; done
40
+ echo " 6B: $(( ANS)) "
0 commit comments