Fifty Shades of Grey

  • Boys and girls are excited to see Fifty Shades of Grey on the silver screen, we just want to code without being bothered, so here's a challenge to pick our brain.



    You have to:




    • Print on the screen fifty squares filled each with a different shade of grey

    • If your language of choice lacks image processing capabilities, you could output an image file

    • Squares must be visible, at least 20 x 20 pixels

    • You cannot use random numbers unless you make sure each shade is unique.

    • You cannot connect to any service over any network

    • You cannot read any files in your program.

    • You cannot use any libraries out of the standard libraries of your language of choice.



    This is code golf so shortest code wins.


    Were they bothering us?

    Can't use C++... ;-(

    Can we also generate an image file if our language lacks image processing capabilities?

    @FUZxxl yes, that's ok

    Objection: misleading title!

    Will we see a Piet submission?

    @MukulKumar why not?

    @BWG: presumably Mukul means because C++ has no standard means to access a screen. Terminal, yes, and you could do it assuming certain terminal properties (background colour control codes) and the aspect ratio of the terminal characters (to get a square).

    @SteveJessop I didn't read the request fully, but couldn't you just write a bitmap? The header is pretty trivial, and the rest is just plain bytes.

    @randomra If I could understand what "The interpreter finds the edge of the current colour block which is furthest in the direction of the DP. (This edge may be disjoint if the block is of a complex shape.) The interpreter finds the codel of the current colour block on that edge which is furthest to the CC's direction of the DP's direction of travel. (Visualise this as standing on the program and walking in the direction of the DP; see table at right.)" meant, I would be working on a Piet submission

    @BWG: that's what the CJam answer below does, so of course you *could* do that. It's clearly not what the question says, but I think the questioner has been overruled by the voters.

    Not the pictures I thought we'd be generating for a 50 shades of grey contest.

    Is jquery allowed?

    Do black and white count as shades of grey? Or should they be excluded?

    *devil in the details

    @BWG Oh...I was so much immersed in array handling that I forgot to use graphical header files....LOL I was still thinking of ASCII characters....:P

    @SalmonKiller Sure, if you include jquery.js in the byte count.

    Why has not the shortest code won?

    @Steffen sorry I thought that was the shortest answer that didn't break any of the rules, what is the answer that you mention?

    What about sanchises "MATLAB, 24 bytes"?

    @Steffen you're right, thanks!

    Now that *Fifty Shades Darker* has come out, should we make all these answers darker by 50 shades?

  • Sanchises

    Sanchises Correct answer

    6 years ago

    MATLAB, 24 bytes


    Second attempt, now actually conforming to the rules.


    imshow(0:1/49:1,'I',2e3)

    The 'I' stands for 'InitialMagnification', but apparently Matlab will autocomplete names in name/value pairs. Sure is a good golfing trick!


    enter image description here


License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM