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 <bits/stdc++.h>
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
int to_int(string s){
	int k=1,res=0;
	for(int i=s.size()-1;i>=0;i--){
		if('0'<=s[i]&&s[i]<='9'){
			res+=k*(s[i]-'0');
		}else{
			res+=k*(s[i]-'a'+10);
		}
		k*=16;
	}
	return res;
}

int main(){
	string ans[2][2][2];
	ans[0][0][0]="black";
	ans[0][0][1]="blue";
	ans[0][1][0]="lime";
	ans[0][1][1]="aqua";
	ans[1][0][0]="red";
	ans[1][0][1]="fuchsia";
	ans[1][1][0]="yellow";
	ans[1][1][1]="white";
	char s[8];
	while(scanf("%s",s)&&s[0]!='0'){
		int a,b,c,dat[3];
		for(int i=1;i<6;i+=2){
			string tmp;int ans[3];
			tmp.assign(s,i,2);
			int d=to_int(tmp);
			if(d<=(to_int("ff")-d))ans[i/2]=0;
			else ans[i/2]=1;
		}
		cout<<ans[dat[0]][dat[1]][dat[2]]<<endl;
	}
}

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

int main() {
	while(1){
		string str; cin >> str ; if(str=="0") break;
		int Color[3]={0};
		for(int i=1;i<str.size();i+=2){
			char ch[2];
			ch[0]=str[i],ch[1]=str[i+1];
			int tmp=0;
			for(int j=0;j<2;j++){
				if('0'<=ch[j] && ch[j]<='9') tmp+=(ch[j]-'0');
				else if('a'<=ch[j] && ch[j]<='f') tmp+=(ch[j]-'a')+10;
				if(j==0) tmp*=16;
			}
			Color[(int)( (i-1)/2 )] = tmp;
		}
		int samp[8][3]; memset(samp,0,sizeof(samp));
		samp[1][2]=samp[2][1]=samp[3][1]=samp[3][2]=255;
		samp[4][0]=samp[5][0]=samp[5][2]=samp[6][0]=samp[6][1]
		=samp[7][0]=samp[7][1]=samp[7][2]=255;
		string tmp[8];
		tmp[0]="black", tmp[1]="blue", tmp[2]="lime", tmp[3]="aqua",
		tmp[4]="red", tmp[5]="fuchsia", tmp[6]="yellow", tmp[7]="white";
		long MIN=0; for(int i=0;i<3;i++) MIN+=Color[i]*Color[i];
		string ans="black";
		for(int i=1;i<8;i++){
			long TMP=0;
			for(int j=0;j<3;j++) TMP+=(Color[j]-samp[i][j])*(Color[j]-samp[i][j]);
			if(TMP<MIN) MIN=TMP, ans=tmp[i];
		}
		cout << ans << '\n' ;
	}
}

C++: #include<stdio.h>
#include<stdlib.h>
char c[8];
char d[3];
char ret[8][10]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
int R[]={0,0,0,0,255,255,255,255};
int G[]={0,0,255,255,0,0,255,255};
int B[]={0,255,0,255,0,255,0,255};
int main(){
	while(1){
		scanf("%s",c);
		if(c[0]!='#')return 0;
		d[0]=c[1];
		d[1]=c[2];
		d[2]='\0';
		int r=strtol(d,NULL,16);
		d[0]=c[3];
		d[1]=c[4];
		int g=strtol(d,NULL,16);
		d[0]=c[5];
		d[1]=c[6];
		int b=strtol(d,NULL,16);
		int min=99999999;
		int at=0;
		for(int i=0;i<8;i++)
			if(min>(r-R[i])*(r-R[i])+(g-G[i])*(g-G[i])+(b-B[i])*(b-B[i])){
				min=(r-R[i])*(r-R[i])+(g-G[i])*(g-G[i])+(b-B[i])*(b-B[i]);
				at=i;
			}
		
		printf("%s\n",ret[at]);
	}
}

C++: #include<iostream>
#include<string>
#include<cmath>

using namespace std;

void DevideColor(string, int&, int&, int&);
int Atoi16(char);
double Calculate(int, int, int, int, int, int);

int main(){
  int i, Red, Green, Blue;
  double min, font[8];
  string Color, StrongColor;
  string color[8] = {"black", "blue", "lime", "aqua", "red", "fuchsia","yellow", "white"};

  while(1){
    cin >> Color;
    if(Color == "0") break;

    DevideColor(Color, Red, Green, Blue);

    font[0] = Calculate(Red, Green, Blue, 0, 0, 0);
    font[1] = Calculate(Red, Green, Blue, 0, 0, 225);
    font[2] = Calculate(Red, Green, Blue, 0, 225, 0);
    font[3] = Calculate(Red, Green, Blue, 0, 225, 225);
    font[4] = Calculate(Red, Green, Blue, 225, 0, 0);
    font[5] = Calculate(Red, Green, Blue, 225, 0, 225);
    font[6] = Calculate(Red, Green, Blue, 225, 225, 0);
    font[7] = Calculate(Red, Green, Blue, 225, 225, 225);

    min = font[0];
    StrongColor = color[0];

    for(i=1; i<8; ++i){
      if(font[i] < min){
        min = font[i];
        StrongColor = color[i];
      }
    }

    cout << StrongColor << endl;
  }

  return 0;

}

void DevideColor(string s, int& r, int& g, int& b){
  string R, G, B;
  copy(s.begin()+1, s.begin()+3, back_inserter(R));
  copy(s.begin()+3, s.begin()+5, back_inserter(G));
  copy(s.begin()+5, s.end(), back_inserter(B));
  r = Atoi16(R[0])*16 + Atoi16(R[1]);
  g = Atoi16(G[0])*16 + Atoi16(G[1]);
  b = Atoi16(B[0])*16 + Atoi16(B[1]);
}

int Atoi16(char c){
  int x;
  if(c >= '0' && c <= '9')
    x = c - 48;
  else
    x = c - 87;
  return x;
}

double Calculate(int r, int g, int b, int _r, int _g, int _b){
  int R, G, B;
  R = r - _r;
  G = g - _g;
  B = b - _b;
  return sqrt(R*R + G*G + B*B);
}

C++: #include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main() {
	string a;
	string c[8] = { "black","blue","lime","aqua","red","fuchsia","yellow","white" };
	int d[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} };
	while (cin>>a&&a!="0")
	{
		double t[3];
		for (int i = 1; i < a.length(); i += 2) {
			double b = 0;
			for (int j = 0; j <= 1; j++) {
				if ((int)a[i + j] >= '0' && (int)a[i +j] <= '9')
					b += (pow(16, (j+1)%2)*(int)(a[i +j] - '0'));
				else 
					b += (pow(16, (j+1)%2)*(10 + (int)a[i + j] - 'a'));
			}
			t[(i - 1) / 2] = b;
		}
		double e = 100000;
		string f = "";
		for (int i = 7; i >= 0; i--) {
			double g = sqrt(pow((t[0] - d[i][0]), 2) + pow((t[1] - d[i][1]), 2) + pow((t[2] - d[i][2]), 2));
			if (g <= e) {
				e = g;
				f = c[i];
			}
		}
		cout << f << endl;
	}
}

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

int parse(string s){
	int tmp = 0;
	if(s[0] >= 'a' && s[0] <= 'f') tmp = s[0] - 'a' + 10;
	else tmp = s[0] - '0';
	if(s[1] >= 'a' && s[1] <= 'f') tmp = tmp * 16 + s[1] - 'a' + 10;
	else tmp = tmp * 16 + s[1] - '0';
	return tmp;
}

int main(){
	string s;
	string name[] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};
	int color[3][8] = {{0,0,0,0,255,255,255,255},{0,0,255,255,0,0,255,255},{0,255,0,255,0,255,0,255}};
	while(1){
		int d[8] = {};
		cin >> s;
		if(s == "0") break;
		for(int i = 0;i < 3;i++){
			int num = parse(s.substr(i * 2 + 1,2));
			for(int j = 0;j < 8;j++){
				d[j] += (num - color[i][j]) * (num - color[i][j]);
			}
		}
		int mi = 1e+9,clr;
		for(int i = 0;i < 8;i++){
			if(mi > d[i]){
				mi = d[i];
				clr = i;
			}
		}
		cout << name[clr] << endl;
	}
	return 0;
}