3
\$\begingroup\$

If you're sad, that's wrong. We need to scrub out ALL sadness.

This is a sad face, for reference:

  ......  
  .S..S.  
 ........ 
 ...SS... 
..SS..SS..
.S......S.
 ........ 

Where S is a consistent pixel, . is any pixel other than S, and is any pixel. Note that the sad face is not a perfect square, only the . should be considered. Theoretical sad face overlap in the corners is possible, but overwriting one sad face has a chance to eliminate the other, e.g. if it was in a . character and is overwritten with an S.

Input

An image, in any acceptable format. I would recommend a color matrix.

Output

The same image, but take all those treasonous sad faces and replace their S characters with randomized data. The data should be either random RGB values, or values taken from the palette of the image. You just need to have a nonzero probability of all outputs; you do not need to make it uniform.

Rules

  • S can be any pixel, as long as it's the same pixel throughout the formation.
  • Remove ALL sad faces. If the removal makes a new sad face, then remove that too.
  • You should only modify S pixels. Unauthorized modification of pixels is insubordination, punishable by disqualification.
  • The shortest answer in bytes wins.

Test Cases

These have one sad face each:

This has 2 sad faces, on the left and right:

This has 2 sad faces overlapping:

This has 2 sad faces, in the top-left and bottom-right; the bottom-left and top-right have S characters in the place of . characters:

\$\endgroup\$
  • \$\begingroup\$ Why not replace all pixels with white pixels? \$\endgroup\$ – anatolyg Dec 6 '17 at 17:21
  • 1
    \$\begingroup\$ @anatolyg because then it won't be replacing it with randomized data. also, if i make a sad face that's black-on-white and then run it through this program, it will still look like a sad face as long as enough of the randomized data is dark enough :p \$\endgroup\$ – HyperNeutrino Dec 6 '17 at 17:31
  • 1
    \$\begingroup\$ @StephenLeppik doesn't this work? pastebin.com/T8mYQx8B To clarify: I meant overlap the square boundary, not the happy face itself \$\endgroup\$ – Rɪᴋᴇʀ Dec 13 '17 at 15:16
  • \$\begingroup\$ @Riker oh, yeah that would be acceptable. \$\endgroup\$ – Nissa Dec 13 '17 at 15:19
  • \$\begingroup\$ @Riker it's open now; you can post your solution. \$\endgroup\$ – Nissa Dec 13 '17 at 19:53
2
\$\begingroup\$

C (gcc), 339 337 331 323 bytes

  • Saved two eight fifteen sixteen bytes thanks to ceilingcat.
C,a,l,A,m,i,t,o,u,s;n(e,z,Z)int*e;{for(C=1;C;C+=i)for(C=s=0;s<Z;s++)for(u=0;u<z;u++)if(u>8&s>5)for(m=e[~-u+~-s*z],A=i=1;++A<4;)for(o=0;o<7;o++)for(t=0;t<10;t++)a=e[l=u+t-9+(s+o-6)*z],(o-1||t-3&&t-6)*(o-3||t<4|5<t)*(o-4||t<2|3<t&t<6|7<t)*(o-5||t-1&&t-8)?o>1|t>1&t<8&o<2|o>3&o<6|t&&t<9&&(i*=a-m):A<3?i*=a==m:i?e[l]=rand():e;}

Try it online!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.