Skip to content

Instantly share code, notes, and snippets.

@lemanschik
Last active December 4, 2025 08:23
Show Gist options
  • Select an option

  • Save lemanschik/754328148508c4f2a329ce25444f0d28 to your computer and use it in GitHub Desktop.

Select an option

Save lemanschik/754328148508c4f2a329ce25444f0d28 to your computer and use it in GitHub Desktop.
for cop
mapfile -t G < input.txt
for y in ${!G[@]};do
for((x=0;x<${#G};x++));do
[[ ${G[y]:x:1} < @ ]]||{
n=0;for i in {0..8};do
(( (Y=y+i/3-1) >= 0 & (X=x+i%3-1) >= 0 )) && \
[[ ${G[Y]:X:1} == @ ]] && ((n++));done
((n<5))&&((t++));}
done;done;echo $t
@lemanschik
Copy link
Author

declare -A g;y=1
while read -r l;do n=${#l};for((x=1;x<=n;x++));do g[$x,$y]=${l:x-1:1};done;((y++));done
for((Y=1;Y<y;Y++));do for((X=1;X<=n;X++));do
[[ ${g[$X,$Y]} == @ ]]&&{ c=0;for a in {0..8};do
[[ ${g[$((X+a/3-1)),$((Y+a%3-1))]} == @ ]]&&((c++));done
((c<5))&&((m++));};done;done;echo $m

@lemanschik
Copy link
Author

part 2

mapfile -t G < input.txt
while :;do D=""
for y in ${!G[@]};do for((x=0;x<${#G};x++));do
[[ ${G[y]:x:1} < @ ]]||{ n=0;for i in {0..8};do
((Y=y+i/3-1,X=x+i%3-1));((Y>=0&&X>=0))&&[[ ${G[Y]:X:1} == @ ]]&&((n++));done
((n<5))&&D+="$y,$x ";}
done;done;[[ -z $D ]]&&break
for p in $D;do y=${p%,*};x=${p#*,};G[y]=${G[y]:0:x}.${G[y]:x+1}
((T++));done;done;echo $T

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment