Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Scenario: while programming you have a sudden nostalgic urge for the '80s and cheesy games.

Requirements: Make a GUI program (text probably won't work) for Simon, the game. Input can be clicking, or pressing a key. You should divide the screen into 4 regions: yellow, blue, red, green. When the game starts, a random color lights up and you activate it. Then, two lights come on, one after the other, and you need to activate those in order, etc. The game ends when you press the wrong color.


-100 if you include sound (a different note played when pressing each region and when the game shows you the colors)

-25 if you include a score counter.

share|improve this question
GUI and code-golf don't generally work together. – user80551 Mar 29 '14 at 6:40
This should be doable in Minecraft. Wouldn't surprise me if someone already has. Don't know how one'd submit that here though... – Kninnug Mar 29 '14 at 10:58
@Kninnug the amount of blocks * bytes per block;) – Outlaw Lemur Mar 29 '14 at 18:08
up vote 10 down vote accepted

Bash 318 297 281 273 268 244 240-125=115

This is primarily a response to "Text probably won't work"; the following text-based bash script runs fine in Konsole, gnome-terminal etc. on my Ubuntu 14.04 machine. To create the regions of colour it sets the text background color. In fact, adding text makes the game more accessible to color-blind players. To make the game yet more accessible it reads the characters that the player needs to press (it assumes that espeak is installed). It also assumes that the only file matching /d*/ur*/ is /dev/urandom. For the regions of color to be of non-trivial size you probably want to set the text size to be quite large. Also if you want the regions of color to be quadrants, you have to run it in a terminal that is two characters wide.

To play press y, r, g or b as appropriate.

d(){ echo cx1r09mRx2g10mGx3y11mYx4b14mBx0m$s|sed s/.$1"//
s/x/[48;5;/g";};x(){ d $c;espeak $c;d j;};l(){
for c in $o;{ eval $1;x;};};f(){ o=$o\ `tr -dc yrgb</d*/ur*|head -c1`
l;l 'read -n1 i;[ $c = $i ]||exit;let s++';f;};f

This solution contains two non-printable ESC characters.

See also the original ungolfed version, and the slightly more playable 256 byte version.

The screenshots below are when the yellow light is on and the player's score is 7. The screenshot on the right has been desaturated to simulate colour-blindness.


share|improve this answer
Way too big for a code golf... – Jan Dvorak Mar 29 '14 at 7:02
True. I am here more for the "Programming Puzzles" more than the "Code Golf". – gmatht Mar 29 '14 at 7:06
I have slightly golfed it now. – gmatht Mar 29 '14 at 11:25

Scratch, 150 – 125 = 25

I'm here for the fun, not the golf.

Edit: The scoring is based on this proposal at the moment. If another scoring system is generally adopted here, feel free to notify me or to edit this answer! For a break-down of this count, please see the comments.

Main program:


Individual sprites:


This is the sprite with number 0. The other sprites have the same script, except the number.

Play with it online.



Note: Please do not press two buttons within 0.3 seconds.

share|improve this answer
Ha, that's cool. A pause after a correct answer would be good, though, or some congratulatory sound. It sounds like my last move is part of the pattern. Also, I would play the sounds more slowly than the input cap, since rhythm and tone matching is how people (myself, at least) play... still, I like it. +1 – krs013 Mar 29 '14 at 8:56
Scratch? Srs? Also, the byte count imo should be the total size of the SB2. – cjfaure Mar 29 '14 at 11:06
@Trimsty Then it would be 126833 bytes (including the wav sound files etc), which is why I said "I'm here for the fun, not the golf." – ace Mar 29 '14 at 11:11
According to the scoring I suggested here, the score is 60 (27 blocks, 20 chars/digits in constants, 8 operators, 5 variable uses). With bonuses, you get -65. – ugoren Mar 30 '14 at 6:34
@ugoren This is actually only a partial answer. There are 4 sprites, and only the script for one is shown, since the other sprites have almost identical scripts except the number. I will update the answer based on your scoring. Thanks. – ace Mar 30 '14 at 15:53

Mathematica, 409 - 125 = 284

k = 2;
p = Tuples[{0, 1}, 2];
f[c_, p_] := 
 EventHandler[{c, Rectangle[p]}, 
  "MouseClicked" :> (AppendTo[x, p]; Beep[]; g)]
h[R_] := (i = 1; 
   H = If[OddQ@i, 
     Beep[]; {EdgeForm[{Thickness[0.02], Black}], FaceForm[], 
      Rectangle@R[[Ceiling[i/2]]]}, {}]; i++, {.3, 2 Length@R}])
s := (m = 0; x = {}; h[R = RandomChoice[p, k]];)
g := (m++; If[Take[R, m] != x, k = 2; s, If[m == k, k++; s]])
Dynamic@Graphics[{MapThread[f, {{Yellow, Red, Blue, Green}, p}], H}, 
  PlotLabel -> k]

enter image description here

share|improve this answer

Windows PowerShell (CLI), 272 - 100 - 25 = 147

$d={param($c)cls;sleep -m 99;'R','Y','Blu','Gre'|
%{Write-Host '#' -N -F "$(if($i%4-ne $c){'Dark'})$_";
$i++}};$b={param($c)&$d $c;[console]::Beep(($c+1)*99,700);&$d};
$m=@();$s=0;for(){$m+=0..3|Get-Random;$m|%{&$b $_};$m|%{
if((read-host)-ne $_){$s;exit}&$b $_};$s++;sleep 1}

I've added newlines here to avoid side-scrolling, but it works as one line so the character count is without newlines.

Screenshot: Screenshot of game playing

To play:

  • Open PowerShell ISE (v3), paste script into text editor, press F5 to run.
  • Game will light up a color, play a sound, then wait for input
  • Press a number (0=red, 1=yellow, 2=blue, 3=green) then Enter.
  • If you are wrong it prints the score and quits. (NB. it might exit your console).
  • If you are right it goes for two notes.
  • You have to press Enter between each note when playing the sequence back.


  • "divide the screen into 4 regions" - you didn't say they had to be quarters, so they aren't.
  • It's hard to see blue light up on the blue background, but it does.
  • Please run in PowerShell ISE - in the normal prompt "DarkYellow" shows as white.
  • You could arguably golf another 28 characters off by removing some of the timing (still making the game playable), and by interpreting the rule "sound (a note played when pressing and when the game shows you the colors)" to mean "they can all be the same sound - default error DING", but I think that's too far against the spirit of it.
share|improve this answer

ZXBasic: 422 - 100 - 25 = 297

This definitely counts as a nostalgic urge for the '80s...

ZXBasic uses a combination of FreeBASIC type commands and ZX Spectrum BASIC to allow loops and repeats which then turn into TZX format to load into a Spectrum emulator.

This version changes the border (although a legend on screen says which key to press). It plays the same notes as original Simon game (

d=0.5:s=0:l=1:t=1:n$="4261":dim m(4)=>{-8,9,1,4}
border 7
while l>0
 cls:a$="":print at 1,1;"Level: ";t;at 2,1;"Score:";s::for i=1 to 4:print at 0,i;paper val(n$(i));ink 0;i:next
 for i=1 to t
  border val(n$(c)):beep d,m(c):border 7
 print at 10,1;"your turn"
  pause 100:k$=inkey:print at 6,i;k$
  if k$=a$(i) then s=s+1:print at 2,7;s:beep d,m(val(k$)):i=i+1
  else l=l-1:i=t+1:print "bad luck!"
  end if
 loop until i>t 
 t=t+1:pause 25
end while

Best score In play

share|improve this answer

HTML5 and Javascript, 1118-100-25=993 bytes

enter image description here

Way too bloated HTML+Js version.

Plays sounds through the Web Audio API.

Frequencies of the notes should be the original Simon's ones, colours and colour placement too.

There is an online demo here: Works in Web Audio compliant browsers (at least Chrome and Firefox, IE doesn't support it, AFAIK).

var hc=["#0f0","red","#ff3","blue"],lc=["#090","#930","#cc0","#33c"],nt=[391,329,261,195],ln=[],qpos=0,pm=0,x,ct=new AudioContext;function ps(a,d){var b=ct.createOscillator();b.frequency.value=d;b.connect(ct.destination);var c=ct.createGain();b.connect(c);c.connect(ct.destination);c.gain.value=-.5;x[a].style.backgroundColor=hc[a];b.start(0);setTimeout(function(a,b){a.stop(0);x[b].style.backgroundColor=lc[b]},500,b,a)}
function w(a){2==pm&&(a!=ln[qpos]?(pm=3,document.getElementsByTagName("span")[0].innerHTML="game over!",ps(a,156)):(qpos++,ps(a,nt[a]),qpos>=ln.length&&(pm=qpos=0)))}function ml(){if(0==pm)document.getElementsByTagName("div")[0].innerHTML=ln.length,ln.push(Math.floor(4*Math.random())),pm=1;else if(1==pm){var a=ln[qpos];qpos<ln.length?(ps(a,nt[a]),qpos++):(qpos=0,pm=2)}setTimeout(ml,500)}window.onload=function(){setTimeout(ml,1);x=document.getElementsByTagName("td")};</script><div>0</div><table cellpadding=40><tr><td bgcolor=#090 onmousedown=w(0)><td bgcolor=#930 onmousedown=w(1)><tr><td bgcolor=#cc0 onmousedown=w(2)><td bgcolor=#33c onmousedown=w(3)></table><span></span>

My record is 15 (I'm pretty bad at this game). What's yours?

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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