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 <stdio.h>
#include <stdlib.h>
#include <string>
#include <cmath>

using namespace std;

int colorCalc(char c1, char c2)
{
	int color = 0;
	if('a' <= c1 && c1 <= 'f')
	{
		color += (c1 - 'a' + 10) * 16;
	}
	else
	{
		color += (c1 - '0') * 16;
	}
	if('a' <= c2 && c2 <= 'f')
	{
		color += c2 - 'a' + 10;
	}
	else
	{
		color += c2 - '0';
	}
	return(color);
}
void solve()
{
	int colors[9][4] = {{{0},   {0},   {0}}, 
						{{0},   {0},   {255}}, 
						{{0},   {255}, {0}}, 
						{{0},   {255}, {255}}, 
						{{255}, {0},   {0}}, 
						{{255}, {0},   {255}}, 
						{{255}, {255}, {0}}, 
						{{255}, {255}, {255}}};
	string name[9] = {"black", 
					  "blue", 
					  "lime", 
					  "aqua", 
					  "red", 
					  "fuchsia", 
					  "yellow", 
					  "white"};
	string str;
	while(cin >> str, str != "0")
	{
		int r = colorCalc(str[1], str[2]);
		int g = colorCalc(str[3], str[4]);
		int b = colorCalc(str[5], str[6]);
		int min = 999999999;
		int label = 0;
		for(int i = 0; i < 8; ++i)
		{
			int sum = sqrt((double)(r - colors[i][0]) * (r - colors[i][0]) + (g - colors[i][1]) * (g - colors[i][1]) + (b - colors[i][2]) * (b - colors[i][2]));
			if(sum < min)
			{
				min = sum;
				label = i;
			}
		}
		cout << name[label] << endl;
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 1<<30

int main() {
  string color[] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
  string s;
  while(cin >> s, s!="0") {
    int rgb[3];
    REP(i,3)
      sscanf(s.substr(i*2+1,2).c_str(), "%x", rgb+i);
    
    int mi = INF;
    int ans;
    REP(i,8) {
      int hoge = 0;
      REP(j,3) {
        if (i>>j & 1)
          hoge += pow(255 - rgb[j], 2);
        else
          hoge += pow(rgb[j], 2);
      }
      if (hoge < mi) {
        mi = hoge;
        ans = i;
      }
    }
    cout << color[ans] << endl;
  }
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define ERASE(v,i) (v).erase(remove(all(v),i),(v).end())
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define debug(x) cerr<<#x<<" = "<<(x)<<endl;
#define LINE cerr<<"LINE: "<<__LINE__<<endl;
inline int toInt(string s){int v;istringstream i(s);i>>v;return v;}
template<class T> inline string toString(T x){ostringstream o;o<<x;return o.str();}
template<class T> void pv(T a,T b){for(T it=a;it!=b;++it)cerr<<*it<<" ";cerr<<endl;}
const int INF = 1000000000;
const double PI = acos(-1.0), EPS = 1e-10;

map<string, int> hex_table;

void table_init() {
	hex_table.clear();
	string table = "0123456789abcdef";
	for(int i = 0; i < 16; i++)
		for(int j = 0; j < 16; j++)
			hex_table[table.substr(i,1) + table.substr(j,1)] = i * 16 + j;
}

int hex2dec(string H) {
	return hex_table[H];
}

string name[] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
string color_code[] = {"000000", "0000ff", "00ff00", "00ffff", "ff0000", "ff00ff", "ffff00", "ffffff"};

int color_value[8][3];

inline double POW(double v) {
	return v * v;
}

void color_value_init() {
	for(int i = 0; i < 8; i++) {
		string R = color_code[i].substr(0, 2);
		string G = color_code[i].substr(2, 2);
		string B = color_code[i].substr(4, 2);
		color_value[i][0] = hex2dec(R);
		color_value[i][1] = hex2dec(G);
		color_value[i][2] = hex2dec(B);
	}
}

int main() {
	table_init();
	color_value_init();
	for(string line; getline(cin, line), line != "0";) {
		int R = hex2dec(line.substr(1, 2));
		int G = hex2dec(line.substr(3, 2));
		int B = hex2dec(line.substr(5, 2));
#if 0
		debug(hex2dec(R));
		debug(hex2dec(G));
		debug(hex2dec(B));
#endif

		int idx = -1;
		double vmin = 1e10;
		for(int i = 0; i < 8; i++) {
			double v = sqrt(POW(R - color_value[i][0]) + POW(G - color_value[i][1]) + POW(B - color_value[i][2]));
			if(v < vmin) {
				idx = i;
				vmin = v;
			}
		}

		cout << name[idx] << endl;
	}
	return 0;
}