Message Boards Message Boards

Code golf chromostereopsis illusion

Posted 5 months ago

I talk about this illusion in my Linkedin series. I am trying to maximally shorten the code (code golf) for chromostereopsis illusion by Akiyoshi Kitaoka:

The point is to make it: (1) identical to his image, (2) make code as short as possible. My take is below. Can you post a shorter answer? Least number of characters wins. Please mention count of characters in your answer. Mine is 150. I prefer to keep randomness free of fix (like SeedRandom). By identical image I meant basic image parameters -- size of objects and image.


enter image description here

POSTED BY: Vitaliy Kaurov
8 Replies

I talk about this illusion in my Linkedin series. Amazing 66 characters solution by Adam on Mathematica Stack Exchange Code Golf I hosted:


That was a play on another amazing 74 characters solution by @Greg Hurst


Yet another version I enjoyed was solution by Azerbajdzan with 80 characters:


enter image description here

POSTED BY: Vitaliy Kaurov
Posted 5 months ago

There are several interesting solutions in the MSE crosspost.

POSTED BY: Rohit Namjoshi

Rearranging to remove r (combined with the tips from the other responses) can get it down to 109 characters:


Edit: Swapped RandomChoice[{…}] for RandomChoice@{…} to remove 1 character.

POSTED BY: Daniel Robinson

Nested If is smaller than Which in this case... If[f < 300, r[{b, Red}], If[f < 440, b, r[{b, Blue}]]]

POSTED BY: Jon McLoone

-17 characters:


Very nice sugar syntax shaving off. And I forgot about compactness of Array. Thank you :-)

POSTED BY: Vitaliy Kaurov

It is a trivial change, but anyway: If the obsolete


gets replaced by


one character is saved.

POSTED BY: Henrik Schachner

Annother (trivial) variation to Ian's elegant approach: The definition of b=Black; is not necessary - you just write Black as 1:

r = RandomChoice; ArrayPlot[Array[(f = #^2 + #2^2;Which[f < 300, r@{1, Red}, f < 400, 1, True, r@{1, Blue}]) &, {57,57}, -28], PlotRangePadding -> 0]

This uses 125 characters.

POSTED BY: Henrik Schachner
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract