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

This is a sad face, for reference:


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.


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


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.


  • 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:

  • \$\begingroup\$ Why not replace all pixels with white pixels? \$\endgroup\$
    – anatolyg
    Dec 6, 2017 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\$
    – hyper-neutrino
    Dec 6, 2017 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\$
    – Riker
    Dec 13, 2017 at 15:16
  • \$\begingroup\$ @Riker oh, yeah that would be acceptable. \$\endgroup\$
    – Nissa
    Dec 13, 2017 at 15:19
  • \$\begingroup\$ @Riker it's open now; you can post your solution. \$\endgroup\$
    – Nissa
    Dec 13, 2017 at 19:53

1 Answer 1


C (gcc), 339 337 331 323 bytes

  • Saved two eight fifteen sixteen bytes thanks to ceilingcat.

Try it online!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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