Go: package main

import (
	"fmt"
	"math"
	"strconv"
)

// ColorCode is a string like #rrggbb
type ColorCode string

// ColorName is a name of color
type ColorName string

// Color has colorname and colorcode
type Color struct {
	name ColorName
	code ColorCode
}

// ColorTable has default colors
type ColorTable struct {
	colors []Color
}

var (
	colorTable = ColorTable{
		[]Color{
			Color{"black", "#000000"},
			Color{"blue", "#0000ff"},
			Color{"lime", "#00ff00"},
			Color{"aqua", "#00ffff"},
			Color{"red", "#ff0000"},
			Color{"fuchsia", "#ff00ff"},
			Color{"yellow", "#ffff00"},
			Color{"white", "#ffffff"},
		},
	}
)

func main() {
	var code ColorCode
	fmt.Scanf("%s", &code)
	for {
		if code == "0" {
			break
		}
		name := colorTable.getNearestColor(code)
		fmt.Println(name)
		fmt.Scanf("%s", &code)
	}
}

func (colorstr ColorCode) parseColorValue() (float64, float64, float64) {
	rr, gg, bb := colorstr[1:3], colorstr[3:5], colorstr[5:7]
	rri, err1 := strconv.ParseUint(string(rr), 16, 8)
	ggi, err2 := strconv.ParseUint(string(gg), 16, 8)
	bbi, err3 := strconv.ParseUint(string(bb), 16, 8)
	if err1 != nil || err2 != nil || err3 != nil {
		err := fmt.Errorf(
			"Failed to read color strings, color code:%s, err: %v %v %v",
			colorstr, err1, err2, err3)
		panic(err)
	}
	return float64(rri), float64(ggi), float64(bbi)
}

func (table *ColorTable) getNearestColor(targetcode ColorCode) ColorName {
	var nearestColor ColorName
	var nearestValue = 1e5
	for _, v := range table.colors {
		trr, tgg, tbb := targetcode.parseColorValue()
		prr, pgg, pbb := v.code.parseColorValue()
		// diff := math.Sqrt(
		// 	math.Pow(prr-trr, 2) + math.Pow(pgg-tgg, 2) + math.Pow(pbb-tbb, 2))
		diff := math.Pow(prr-trr, 2) +
			math.Pow(pgg-tgg, 2) +
			math.Pow(pbb-tbb, 2)
		if nearestValue > diff {
			nearestValue = diff
			nearestColor = v.name
		}
	}
	return nearestColor
}

C++: #include <iostream>
#include <string>
using namespace std;

const int MAX_C = 8;

int main() {
	pair< int, string > colors[MAX_C] = {
		make_pair< int, string >(0x000000, "black"),
		make_pair< int, string >(0x0000ff, "blue"),
		make_pair< int, string >(0x00ff00, "lime"),
		make_pair< int, string >(0x00ffff, "aqua"),
		make_pair< int, string >(0xff0000, "red"),
		make_pair< int, string >(0xff00ff, "fuchsia"),
		make_pair< int, string >(0xffff00, "yellow"),
		make_pair< int, string >(0xffffff, "white")
	};
	string color, cname;
	int r, g, b, _r, _g, _b, min, dist;
	
	while(cin >> color, color != "0"){
		r = stoi(color.substr(1, 2), nullptr, 16);
		g = stoi(color.substr(3, 2), nullptr, 16);
		b = stoi(color.substr(5, 2), nullptr, 16);
		
		min = ~(1 << 31);
		cname;
		
		for(int i = 0; i < MAX_C; ++i){
			_r = (colors[i].first & 0xff0000) >> 16;
			_g = (colors[i].first & 0x00ff00) >> 8;
			_b = (colors[i].first & 0x0000ff);
			
			dist = (r - _r) * (r - _r) + (g - _g) * (g - _g) + (b - _b) * (b - _b);
			
			if(dist < min){
				min = dist;
				cname = colors[i].second;
			}
		}
		cout << cname << endl;
	}
	return 0;
}

C++: // 2011/08/21 Tazoe

#include <iostream>
#include <string>
using namespace std;

int main()
{
	while(true){
		string clr;
		cin >> clr;
		if(clr=="0")		// ツ閉カツ篠堋療ア
			break;

		if(clr[1]>='0'&&clr[1]<='7')
			if(clr[3]>='0'&&clr[3]<='7')
				if(clr[5]>='0'&&clr[5]<='7')
					cout << "black" << endl;
				else
					cout << "blue" << endl;
			else
				if(clr[5]>='0'&&clr[5]<='7')
					cout << "lime" << endl;
				else
					cout << "aqua" << endl;
		else
			if(clr[3]>='0'&&clr[3]<='7')
				if(clr[5]>='0'&&clr[5]<='7')
					cout << "red" << endl;
				else
					cout << "fuchsia" << endl;
			else
				if(clr[5]>='0'&&clr[5]<='7')
					cout << "yellow" << endl;
				else
					cout << "white" << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <cmath>
int hextodec(char h){
  int res;
  if(h >= '0' && h <= '9')
    res = h - '0';
  else
    res = h - 'a' + 10;
  return res;
}

int main(){
  int color[8][3] = {{0, 0, 0}, {0, 0, 256}, {0, 256, 0},
                     {0, 256, 256}, {256, 0, 0}, {256, 0, 256},
                     {256, 256, 0}, {256, 256, 256}};
  std::string name[8] = {"black", "blue", "lime",
                         "aqua", "red", "fuchsia",
                         "yellow", "white"};

  std::string c;
  while(std::cin >> c, c.compare("0")){
    int r = hextodec(c[1]) * 16 + hextodec(c[2]),
        g = hextodec(c[3]) * 16 + hextodec(c[4]),
        b = hextodec(c[5]) * 16 + hextodec(c[6]);
    int min_v = 1000000, min_c;
    for(int i=7;i>=0;i--){
      if(color[i][0] == r && color[i][1] == g && color[i][2] == b){
        min_c = i; break;
      }
      int t = pow(r-color[i][0], 2) + pow(g-color[i][1], 2) +
              pow(b-color[i][2], 2);
      if(min_v > t)min_v = t, min_c = i;
    }
    std::cout << name[min_c] << std::endl;
  }
}

C++: #include <iostream>
#include <vector>
#include <sstream>
#include <climits>
//#include <fstream>

using namespace std;

int hex2dec (char c)
{
	if (isdigit(c) ){
		return (c - '0');
	} // end if
	return (c - 'a' + 10 );
}

int main()
{
	const string color[] = {
"black",//	 00	 00	 00
"blue",//	 00	 00	 ff
"lime",//	 00	 ff	 00
"aqua",//	 00	 ff	 ff
"red",//	 ff	 00	 00
"fuchsia",// ff	 00	 ff
"yellow",//	 ff	 ff	 00
"white"//	 ff	 ff	 ff
};
	const int code[][3] = {
/* black */	 {0x00, 0x00, 0x00 },
/* blue */	 {0x00, 0x00,	0xff },
/* lime */	 {0x00, 0xff,	0x00 },
/* aqua */	 {0x00, 0xff,	0xff },
/* red	*/	 {0xff, 0x00,	0x00 },
/* fuchsia */  {0xff, 0x00,	0xff },
/* yellow */	 {0xff, 0xff,	0x00 },
/* white */	 {0xff, 0xff,	0xff }
};

//	cut here before submit 
//	freopen ("testcase.whatcolor", "r", stdin );
	string str = "";

	while (getline (cin, str ) ){
		int len = str.length();

		if (len == 1 && str[0] == '0'){
			break;
		} // end if

		vector <int> C (3, 0 ); // Red, Green, Blue order
		int i,j;

		for (i = 0; i < 3; ++i){
			C[i] = hex2dec(str[2*i+1])*16 + hex2dec(str[2*i+2]);
		} // end for

		int minV = INT_MAX;
		int res = -1;
		for (i = 0; i	< sizeof (color)/sizeof(color[0] ); ++i){
			int dd = 0;
			for (j = 0; j < 3; ++j){
				dd += (code[i][j] - C[j])*(code[i][j] - C[j]);
			} // end for
			
			if (minV > dd ){
				minV = dd;
				res = i;
			} // end if
		} // end for
		
		cout << color[res] << endl;

	} // end loop
		
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
int main(void){
  int col;
  char c;
  while(cin>>c>>hex>>col){
    if(c=='0') break;
    int data[3];
    REP(i,3){
      data[i] = col%256;
      col/=256;
    }
    bool judge[3];
    REP(i,3){
      if(255-data[2-i]<data[2-i]){
        judge[i] = false;
      }else{
        judge[i] = true;
      }
    }
    if(judge[0]){
      if(judge[1]){
        if(judge[2]){
          cout<<"black"<<endl;
        }else{
          cout<<"blue"<<endl;
        }
      }else{
        if(judge[2]){
          cout<<"lime"<<endl;
        }else{
          cout<<"aqua"<<endl;
        }
      }
    }else{
      if(judge[1]){
        if(judge[2]){
          cout<<"red"<<endl;
        }else{
          cout<<"fuchsia"<<endl;
        }
      }else{
        if(judge[2]){
          cout<<"yellow"<<endl;
        }else{
          cout<<"white"<<endl;
        }
      }
    }
  }
  return 0;
}