Skip to main content
1 of 10
Unmitigated
  • 2.8k
  • 1
  • 5
  • 14

Java, 257 bytes

a->{int r=9,i=~r,c[],j,x,y,k,p;l:for(;++i<512;){c=a.clone();for(j=-1;++j<9;)if((i&1<<j)>0)c[j]=7;for(j=p=-1;++j<3;){x=y=0;for(k=-1;++k<9;){if(k/3==j)x+=c[k];if(k%3==j)y+=c[k];}if(p<0)p=x;if(x!=p|y!=p)continue l;}r=Math.min(r,Integer.bitCount(i));}return r;}

Takes a flat array as input. This method tries all 512 (29) possibilities by using the binary representations of the integers from 0 to 511. On each iteration, it clones the input array and sets the values at all indexes where i has a set bit to 7. Then, it checks if the current array is valid, in which case the answer is updated.

Try it online!

Unmitigated
  • 2.8k
  • 1
  • 5
  • 14