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<cmath>
#include<string>
using namespace std;

int Conv(char c1, char c2){
	return (c1-'0')*0x10 + (c2-'0');
}
double dist(int R, int G, int B, int rR, int rG, int rB){
	return sqrt( pow(R-rR,2.0) + pow(G-rG,2.0) + pow(B-rB,2.0) );
}
string judge(int R, int G, int B ){
	double min_dist = 65536;
	string color;

	double r;
	
	r = dist( R, G, B, 0, 0, 0 );
	if( min_dist > r ){
		min_dist = r;
		color = "black";
	}
	r = dist( R, G, B, 0, 0, 0xFF );
	if( min_dist > r ){
		min_dist = r;
		color = "blue";
	}
	r = dist( R, G, B, 0, 0xFF, 0 );
	if( min_dist > r ){
		min_dist = r;
		color = "lime";
	}
	r = dist( R, G, B, 0, 0xFF, 0xFF );
	if( min_dist > r ){
		min_dist = r;
		color = "aqua";
	}
	r = dist( R, G, B, 0xFF, 0, 0 );
	if( min_dist > r ){
		min_dist = r;
		color = "red";
	}
	r = dist( R, G, B, 0xFF, 0, 0xFF );
	if( min_dist > r ){
		min_dist = r;
		color = "fuchsia";
	}
	r = dist( R, G, B, 0xFF, 0xFF, 0 );
	if( min_dist > r ){
		min_dist = r;
		color = "yellow";
	}
	r = dist( R, G, B, 0xFF, 0xFF, 0xFF );
	if( min_dist > r ){
		min_dist = r;
		color = "white";
	}
	return color;
}

int main(){
	while( true ){
		int R;
		int G;
		int B;
		string s;
		cin>>s;
		if(s.compare("0")==0)break;
		R = Conv(s[1],s[2]); G = Conv(s[3],s[4]); B = Conv(s[5],s[6]);
		cout << judge(R,G,B) << endl;
	}
	return 0;
}

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

const int INF = 1 << 28;

int to_hex (char a) {
    if ('0' <= a && a <= '9') return a - '0';
    else return a - 'a' + 10;
}

int main ()
{
    int R[] = {0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff};
    int G[] = {0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff};
    int B[] = {0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff};
    string color[] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};

    string str;
    while (cin >> str, str != "0") {
        int r = to_hex(str[1]) * 16 + to_hex(str[2]);
        int g = to_hex(str[3]) * 16 + to_hex(str[4]);
        int b = to_hex(str[5]) * 16 + to_hex(str[6]);

        int D = INF;
        string res;
        for (int i = 0; i < 8; i++) {
            int d = ((R[i] - r) * (R[i] - r) + (G[i] - g) * (G[i] - g) + (B[i] - b) * (B[i] - b));
            if (d < D) {
                res = color[i];
                D = d;
            }
        }
        cout << res << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <sstream>
#include <string>
using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

using namespace std;

int sq(int n){
    return n*n;
}

int main(){
    char c[10];
    while(cin>>c && c[0]!='0'){
        unsigned md=1<<30;
        int cn;
        unsigned cd=strtoul(c+1,0,16);
        rep(i,8){
            unsigned d=0;
            rep(j,3){
                static const unsigned cc[]={0x0,0xff,0xff00,0xffff,0xff0000,0xff00ff,0xffff00,0xffffff};
                d+=sq((cd>>j*8&0xFF)-(cc[i]>>j*8&0xFF));
            }
            if(d<md){
                md=d;
                cn=i;
            }
        }

        const string cstr[]= {
            "black",
            "blue",
            "lime",
            "aqua",
            "red",
            "fuchsia",
            "yellow",
            "white"
        };
        cout<<cstr[cn]<<endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

typedef pair<double, int> pdi;

int lis[8][3] = {
	{0, 0, 0},
	{0, 0, 0xff},
	{0, 0xff, 0},
	{0, 0xff, 0xff},
	{0xff, 0, 0},
	{0xff, 0, 0xff},
	{0xff, 0xff, 0},
	{0xff, 0xff, 0xff}
};

string color[8] = { "black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white" };

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

int main() {
	string str;
	while (cin >> str, str != "0") {
		int c[3];
		REP(i, 3) { c[i] = 16 * calc(str[1 + i * 2]) + calc(str[1 + i * 2 + 1]); }
		
		vector<pdi> ans;
		REP(i, 8) {
			double d = 0.0;
			REP(j, 3) d += pow(lis[i][j] - c[j], 2.0);
			d = sqrt(d);
			ans.push_back(pdi(d, i));
		}
		sort(ans.begin(), ans.end());
		cout << color[ans[0].second] << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

struct color {
	int r, g, b;
};
map<string, color>mp{
	{"black",{0,0,0}},
	{"blue",{0,0,0xff}},
	{"lime",{0,0xff,0} },
	{"aqua",{0,0xff,0xff}},
	{"red",{0xff,0,0}},
	{"fuchsia",{0xff,0,0xff}},
	{"yellow",{0xff,0xff,0}},
	{"white",{0xff,0xff,0xff}}
};
int main() {
	string s;
	while (cin >> s, s != "0") {
		int r, g, b;
		sscanf(s.data(), "%*c%2x%2x%2x", &r, &g, &b);
		int Min = INT_MAX;
		string ans;
		for (auto p : mp) {
			int d = abs((r - p.second.r)*(r - p.second.r) + (g - p.second.g)*(g - p.second.g) + (b - p.second.b)*(b - p.second.b));
			if (d < Min) {
				Min = d;
				ans = p.first;
			}
		}
		cout << ans << endl;
	}
}