In the color spelling game, you are shown a list of color names, but rather than reading the words that are written, you have to say the name of the color of the letters. The game is over as soon as you say the wrong color, and the player who spelled the most words correctly wins. To make the game more challeging, each word is written on a different background color.

And here is your challenge:

Write a program that creates a color spelling game.

  • Print every second or so the name of a color.
  • Use different colors for the background and the foreground.
  • The name of the color you print should be different than both the background and the foreground.
  • Do not repeat the same color name, foreground or background color in two consecutive rows. It's still ok to reuse the same color in succession for different purposes, like printing the word "red" after a word on a red background.
  • Choose each color (pseudo)randomly from a palette of at least 6 colors.
  • Use a programming language of your choice.

Here is my solution for JavaScript, change as you like: http://jsfiddle.net/xb8rqsbr/

This is a code golf challenge, so keep your code short.

Have fun!

  • 8
    \$\begingroup\$ Why is this a popularity contest? This is quite strictly specified, so where is the room for creativity? Why not make it a simple code golf? \$\endgroup\$ Commented Sep 20, 2014 at 15:34
  • 1
    \$\begingroup\$ Where does spelling appear? Isn't it a color reading task, known as the Stroop Word-Color test? \$\endgroup\$
    – DavidC
    Commented Sep 20, 2014 at 16:38
  • 2
    \$\begingroup\$ Now there's a problem with code-golf: what colors do we need to support? Or may we encode a list for free and have to support any size of the list? \$\endgroup\$ Commented Sep 21, 2014 at 8:41
  • \$\begingroup\$ @JanDvorak you don't need to support any specific color, but the code should work without input, so the color list should be somehow predefined. \$\endgroup\$
    – GOTO 0
    Commented Sep 21, 2014 at 8:50

5 Answers 5


BBC Basic, 187 176 ASCII characters, tokenised filesize 155 140

Download emulator at http://www.bbcbasic.co.uk/bbcwin/bbcwin.html

Saved some characters: instead of using MOD to always generate random numbers that differ than the previous value, I simply generate any number and perform a check instead.

b=0f=0w=0REPEATc=b g=f x=w REPEATb=RND(6)f=RND(6)w=RND(6)UNTIL(b-f)*(f-w)*(w-b)*(b-c)*(f-g)*(w-x)VDU17,b+128,17,f:PRINTMID$("Red LimeGoldBluePinkAqua",w*4-3,4):WAIT 99UNTIL0

I used the original BBC Basic 3-bit colour codings, which are based on 1's bit=Red, 2's bit=Green, 4's bit=Blue. I renamed Yellow as Gold, Magenta as Pink and Green as Lime (justifiable given the shade produced) in order to shorten colour names. I also renamed Cyan as Aqua just because. Therefore I use colours 1 to 6 from the 3-bit scheme. I exclude 0=black and 7=white (a very light grey, as the full white belongs to the extended 16-colour set in which the 8`s bit refers to brightness.)

b=0 f=0 w=0                                     :REM initialise "old" values for background, foreground and word.
  c=b g=f x=w                                   :REM c,g and x contain the old values for background, foreground and word.
    b=RND(6)f=RND(6)w=RND(6)                    :REM pick random numbers between 1 and 6
  UNTIL(b-f)*(f-w)*(w-b)*(b-c)*(f-g)*(w-x)      :REM until all colours are different from each other and their previous values
  VDU17,b+128,17,f,12                           :REM VDU 17 sets colour, using the 128's bit to say if it is foreground or background. VDU 12 clears the screen.
  PRINTMID$("Red LimeGoldBluePinkAqua",w*4-3,4) :REM MID$ picks the colour. The string is considered 1-indexed.
  WAIT 99                                       :REM wait 99 centiseconds


The first few images show the program as written, running in screen mode 6. The bottom image shows the program with the ,12 removed so that the screen is not cleared in between word printings. That way it is easier to verify that the colours comply with the rules.

enter image description here


Algoid - 349

Although Algoid isn't the best for golfing, it's perfect for these types of challenges.

set x=math.random;set m;while(true){set c=array{{"black",0},{"brown",6},{"blue",8},{"green",10},{"red",12},{"yellow",14},{"white",15}};set l=c.length();algo.clear();algo.hide();set b=0;set t=0;set w=0;while(b==t||w==t||b==w){b=c[x(l-1)];t=c[x(l-1)];w=c[x(l-1)]}if(m!=w){algo.setColor(t[1]);algo.setBgColor(b[1]);algo.text(w[0]);util.wait(2000);m=w}}

Example outputs


JavaScript ES6 - 163

Test on Firefox console. I'll try golfing it more later.

  • \$\begingroup\$ "Print every second or so" - if anyone isn't fond of 999, then 1e3 also works. \$\endgroup\$
    – targumon
    Commented Jan 20, 2019 at 23:35

Ruby 165

loop{f,b,t=(0..5).to_a.sample 3
x!=f&&y!=b&&z!=t&&(puts %W{\e[0 \e[3#{f} \e[4#{b} #{%w/black red green brown blue magenta/[t]}}.join ?m
sleep 1




Python - 260

Not amazing, but it works

from random import randint
ps = ['pink','green','yellow','red'];cs=['\033[94m','\033[92m','\033[93m','\033[91m']
print "1 pink, 2 green, 3 yellow, 4 red"
while True:
    if int(g)!=c+1:

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.