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 <cstdio>
#include <cmath>
#include <string>
#include <climits>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
int main(){
	string color[8] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
	int range[8][3] = {{0, 0, 0}, {0, 0, 255}, {0, 255, 0}, {0, 255, 255},
	{255, 0, 0}, {255, 0, 255}, {255, 255, 0}, {255, 255, 255}};
	char s;
	int a, b, c;
	while(scanf(" %c", &s)) {
		if(s == '0') break;
		scanf("%2x%2x%2x", &a, &b, &c);
		int ret = INT_MAX, ans = 0;
		rep(i,8) {
			int buf = (a-range[i][0])*(a-range[i][0]) + (b-range[i][1])*(b-range[i][1]) 
				+ (c-range[i][2])*(c-range[i][2]);
			if(ret > buf) {
				ret = buf;
				ans = i;
			}
		}
		cout << color[ans] << endl;
	}
	return 0;
}

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<bits/stdc++.h>
using namespace std;
int main()
{
    string color[]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
    int colornum[8][3]={{0,0,0},{0,0,255},{0,255,0},{0,255,255},{255,0,0},{255,0,255},{255,255,0},{255,255,255}};
    int value[200]={};
    for(int i=0;i<10;i++)value['0'+i]=i;
    for(int i=0;i<6;i++)value['a'+i]=10+i;
    string str;
    while(cin>>str&&str!="0"){
        int num[3];
        for(int i=0;i<3;i++)num[i]=value[str[1+2*i]]*16+value[str[2+2*i]];
        int ans[8]={};
        for(int i=0;i<8;i++){
            for(int j=0;j<3;j++)ans[i]+=pow(colornum[i][j]-num[j],2);
            ans[i]=sqrt(ans[i]);
        }
        int co=0;
        for(int i=1;i<8;i++)if(ans[co]>ans[i])co=i;
        cout<<color[co]<<endl;
    }
}

C++: #include<iostream>
#include<string>
using namespace std;
string S, x[2][2][2] = { {{"black","blue"}, {"lime","aqua"}}, { {"red","fuchsia"}, {"yellow","white"} } };
char T[9] = "89abcdef";
int a, b, c;
int main() {
	while (true) {
		a = 0; b = 0; c = 0;
		cin >> S;
		if (S == "0") { break; }
		for (int i = 0; i < 8; i++){
			if (T[i] == S[1]) {
				a = 1;
			}
		}
		for (int i = 0; i < 8; i++) {
			if (T[i] == S[3]) {
				b = 1;
			}
		}
		for (int i = 0; i < 8; i++) {
			if (T[i] == S[5]) {
				c = 1;
			}
		}
		cout << x[a][b][c] << endl;
	}
}

C++: #include<iostream>
#include<cmath>
#include<string>
#include<cctype>
#define sq(a) ((a)*(a))
using namespace std;

int Conv(char c1, char c2){
	c1=toupper(c1);
	c2=toupper(c2);
	return (c1-'0')*0x10 + (c2-'0');
}
int dist(int R, int G, int B, int rR, int rG, int rB){
	return sq(R-rR) + sq(G-rG) + sq(B-rB);
}
string judge(int R, int G, int B ){
	int min_dist = 1<<30;
	string color;

	int 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 <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

using T = tuple<double, double, double>;

int f(char c) {
    if (c < 'A') return (c - '0');
    else return (c - 'a') + 10;
}

int main() {
    string name[8] = { "black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white" };
    T color[8];
    color[0] = T(0, 0, 0);
    color[1] = T(0, 0, 255);
    color[2] = T(0, 255, 0);
    color[3] = T(0, 255, 255);
    color[4] = T(255, 0, 0);
    color[5] = T(255, 0, 255);
    color[6] = T(255, 255, 0);
    color[7] = T(255, 255, 255);
    string s;
    while (cin >> s && s != "0") {
        double r = 0, g = 0, b = 0;
        r = 16 * f(s[1]) + f(s[2]);
        g = 16 * f(s[3]) + f(s[4]);
        b = 16 * f(s[5]) + f(s[6]);

        string ans;
        double mind = 1001001;
        for (int i = 0; i < 8; i++) {
            double t = pow(get<0>(color[i]) - r, 2) + pow(get<1>(color[i]) - g, 2) + pow(get<2>(color[i]) - b, 2);
            double diff = sqrt(t);
            if (mind > diff) {
                mind = diff;
                ans = name[i];
            }
        }
        cout << ans << endl;
    }
}