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>
using namespace std;
  
// #define int long long
#define pb push_back
#define print(Target) cout << Target << '\n'

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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}

struct COL{
  double n;
  string name;
};

const int c[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}};

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

bool cmp(COL lhs, COL rhs)
{
  return (lhs.n < rhs.n);
}

signed main()
{
  //ios::sync_with_stdio(false);
  char sr[2], sg[2], sb[2];
  char sh;
    
  while (scanf("%1s", &sh), sh != '0'){
    COL col[8];
    scanf("%2s%2s%2s", sr, sg, sb);
    int r = strtol(sr, NULL, 16),
        g = strtol(sg, NULL, 16),
        b = strtol(sb, NULL, 16);

    REP(i, 8){
      col[i].n = sqrt((c[i][0] - r) * (c[i][0] - r) + (c[i][1] - g) * (c[i][1] - g) + (c[i][2] - b) * (c[i][2] - b));
      col[i].name = s[i];
    }

    sort(col, col + 8, cmp);
    print(col[0].name);
  }

  return (0);
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int a[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}
};
string out[8]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
int main(){
  string in;
  map<char,int>c;
  rep(i,10)c[i+'0']=i;
  loop(i,'a','f'+1)c[i]=i-'a'+10;
  while(cin>>in,in!="0"){
    int min=1e9;
    int mini=1e9;
    int b[3]={c[in[1]]*16+c[in[2]],c[in[3]]*16+c[in[4]],c[in[5]]*16+c[in[6]]};
    //cout<<b[0]<<" "<<b[1]<<" "<<b[2]<<endl;
    rep(i,8){
      double sum=0;
      rep(j,3)sum+=pow(b[j]-a[i][j],2);
      if(min>sum){min=sum;mini=i;}
    }
    cout<<out[mini]<<endl;
  }
}

C++: #include <iostream>
#include <string>
#include <cstdlib>
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 = strtol(color.substr(1, 2).c_str(), NULL, 16);
		g = strtol(color.substr(3, 2).c_str(), NULL, 16);
		b = strtol(color.substr(5, 2).c_str(), NULL, 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++: #include <iostream>
#include <cmath>

using namespace std;

string str;
const string color[8] = {"black","blue","lime","aqua","red","fuchsia",
			 "yellow","white"};
const string strong[8] = {"#000000","#0000ff","#00ff00","#00ffff","#ff0000",
			  "#ff00ff","#ffff00","#ffffff"};

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

int d(string str1,string str2){
  int R1 = change(str1[1])*16 + change(str1[2]);
  int G1 = change(str1[3])*16 + change(str1[4]);
  int B1 = change(str1[5])*16 + change(str1[6]);

  int R2 = change(str2[1])*16 + change(str2[2]);
  int G2 = change(str2[3])*16 + change(str2[4]);
  int B2 = change(str2[5])*16 + change(str2[6]);

  int res = pow(R1-R2,2.0) + pow(G1-G2,2.0) + pow(B1-B2,2.0);

  return res;
}

#define INF (1<<29)

int main(){
  while(cin >> str , str != "0"){
    int min_ = INF,ans;
    for(int i = 0 ; i < 8 ; i++){
      int dist = d(str,strong[i]);
      if(dist < min_){
	min_ = dist;
	ans = i;
      }
    }
    cout << color[ans] << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <cmath>
#include <string>
using namespace std;
double square(int SQ){
	double KAGA;
	KAGA=SQ*SQ;
	return KAGA;
}
int main(){
	string s,kaga="0123456789abcdef";
	string color[8]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
	int RK[8]={0,0,0,0,255,255,255,255};
	int GK[8]={0,0,255,255,0,0,255,255};
	int BK[8]={0,255,0,255,0,255,0,255};
	int C[3];
	double tmp;
	double MIN;
	string ans;
	while(cin>>s,s!="0"){
		for(int i=2,j=0;j<3;i+=2,j++){
			C[j]=0;
			for(int k=0;k<20;k++){
				if(s[i]==kaga[k]){
					C[j]+=k;
					k+=30;
				}
			}
			for(int k=0;k<20;k++){
				if(s[i-1]==kaga[k]){
					C[j]+=k*16;
					k+=30;
				}
			}
		}
		
		ans="?";
		MIN=10000000;
		
		for(int i=0;i<8;i++){
			tmp=sqrt(square(C[0]-RK[i])+square(C[1]-GK[i])+square(C[2]-BK[i]));
			if(MIN>tmp){
				MIN=tmp;
				ans=color[i];
			}
		}
		
		cout<<ans<<endl;
	}
	return 0;
}