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<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
#include <vector>
#include<math.h>
#include<iomanip>
#include<set>


using namespace std;

int a[10][4]={{0,0,0,0},{0,0,265},{0,265,0},{0,265,265},{265,0,0},{265,0,265},{265,265,0},{265,265,265}};
int main(){


	
	while(1){
	string p;
	cin>>p;if(p=="0")return 0;

	int Y[15]={};
	for(int i=1;i<p.size();i++){
		if(p[i]>='0'&&p[i]<='9')Y[i]=p[i]-'0';
		else {Y[i]=10;Y[i]+=p[i]-'a';
		}
	}
	int X[5]={};
	for(int i=0;i<3;i++){
		X[i]+=16*Y[2*i+1];
		X[i]+=Y[2*i+2];
	}
	double ans=0,Bst=9999;
	int k=0;
	double c0=X[0],c1=X[1],c2=X[2];
	for(int i=0;i<8;i++){
		double A=a[i][0]-c0,B=a[i][1]-c1,C=a[i][2]-c2;
		
		ans=sqrt(A*A+B*B+C*C);
		if(ans<Bst){Bst=ans;k=i;}
	}
	if(k==7)cout<<"white"<<endl;
	else if(k==6)cout<<"yellow"<<endl;
	else if(k==5)cout<<"fuchsia"<<endl;
	else if(k==4)cout<<"red"<<endl;
	else if(k==3)cout<<"aqua"<<endl;
	else if(k==2)cout<<"lime"<<endl;
	else if(k==1)cout<<"blue"<<endl;
	else if(k==0)cout<<"black"<<endl;
	}
	}

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

int main()
{
  string s;
  for(;cin>>s,s!="0";)
    {
      int r=0,g=0,b=0;
      for(int i=1;i<3;i++)
	{
	  r*=16;
	  if(s[i]>='0'&&s[i]<='9')
	      r+=s[i]-'0';
	  else
	    r+=s[i]-'a'+10;
	}
      for(int i=3;i<5;i++)
	{
	  g*=16;
	  if(s[i]>='0'&&s[i]<='9')
	      g+=s[i]-'0';
	  else
	   g+=s[i]-'a'+10;
	}
      for(int i=5;i<7;i++)
	{
	  b*=16;
	  if(s[i]>='0'&&s[i]<='9')
	      b+=s[i]-'0';
	  else
	    b+=s[i]-'a'+10;
	}
      string color[]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
      int rk[]={0,0,0,0,0xff,0xff,0xff,0xff};
      int gk[]={0,0,0xff,0xff,0,0,0xff,0xff};
      int bk[]={0,0xff,0,0xff,0,0xff,0,0xff};
      
      int ans=0;
      for(int i=1;i<8;i++)
	{
	  int a1=(r-rk[i])*(r-rk[i])+(g-gk[i])*(g-gk[i])+(b-bk[i])*(b-bk[i]);
	  int a2=(r-rk[ans])*(r-rk[ans])+(g-gk[ans])*(g-gk[ans])+(b-bk[ans])*(b-bk[ans]);
	  // /cout<<a1<<endl;
	  //cout<<a2<<endl;
	  if(a1<a2)
	    ans=i;
	}
      cout<<color[ans]<<endl;
    }
}

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

#define sq(c) ((c)*(c))

vector<double> col8[8];

vector<double> col16to10( string str ) {
  string s;
  
  str = str.substr(1, 6);
  vector<double> col(3);
  for(int i=0; i<3; i++) {
    s = str.substr(i*2, 2);
    if(isalpha(s[1]))	col[i] = s[1]-'a' + 10;
    else col[i] = s[1]-'0';
    
    if(isalpha(s[0]))	col[i] += ( s[0]-'a' + 10 ) * 16;
    else col[i] += ( s[0]-'0' ) * 16;
  }

  return col;
}

double calc( vector<double> col, int i ) {
  return sqrt( sq(col[0]-col8[i][0]) + sq(col[1]-col8[i][1]) + sq(col[2]-col8[i][2]) );
}

int main() {
  string str;
  
  col8[0] = col16to10("#000000");
  col8[1] = col16to10("#0000ff");
  col8[2] = col16to10("#00ff00");
  col8[3] = col16to10("#00ffff");
  col8[4] = col16to10("#ff0000");
  col8[5] = col16to10("#ff00ff");
  col8[6] = col16to10("#ffff00");
  col8[7] = col16to10("#ffffff");
  
  while(getline(cin, str)) {
    if( str == "0" ) break;
    
    vector<double> col(3);
    col = col16to10( str );
    
    double mn = 1<<20;
    int num = 0;
    for(int i=0; i<8; i++) {
      double temp = mn;
      mn = min( mn, calc(col, i) );
      if( mn < temp ) num = i;
    }
    
    switch( num ) {
    case 0: cout << "black"; break;
    case 1: cout << "blue";  break;
    case 2: cout << "lime";  break;
    case 3: cout << "aqua";  break;
    case 4: cout << "red";   break;
    case 5: cout << "fuchsia"; break;
    case 6: cout << "yellow"; break;
    case 7: cout << "white"; break;
    }
    cout << endl;
  }
  
  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 in[256]={0};
int han[3][8]={
  {  0,  0,  0,  0,256,256,256,256},
  {  0,  0,256,256,  0,  0,256,256},
  {  0,256,  0,256,  0,256,  0,256}
};
string ss[8]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
int main(){
  string s;
  loop(i,'0','9'+1)in[i]=i-'0';
  loop(i,'a','g')in[i]=i-'a'+10;
  while(cin>>s,s.size()!=1||s[0]!='0'){
    int a[3]={0};
    rep(i,3){
      a[i]=in[s[2*i+1]]*16+in[s[2*i+2]];
    }
    long long int mi=1000000000;
    int ms;
    rep(i,8){
      long long int sum=0;
      rep(j,3)sum+=(han[j][i]-a[j])*(han[j][i]-a[j]);
      if(mi>sum){
	ms=i;
	mi=sum;
      }
    }
    cout<<ss[ms]<<endl;
  }
}

C++: #include <bits/stdc++.h>

using namespace std;

int hextod(char a,char b){
    int ret=0;
    if(isdigit(b))ret+=b-'0';
    else ret+=10+b-'a';
    if(isdigit(a))ret+=16*(a-'0');
    else ret+=16*(10+a-'a');
    return ret;
}

int main(){
    while(true){
        char un;
        cin>>un;
        if(un=='0')break;
        char r1,r2,g1,g2,b1,b2;
        cin>>r1>>r2>>g1>>g2>>b1>>b2;
        int r,g,b;
        r=hextod(r1,r2);
        g=hextod(g1,g2);
        b=hextod(b1,b2);

        vector<vector<int>> iro(8,vector<int>(3));
        for (int i = 0; i < 8; ++i) {
            if(i%2==0)iro[i][0]=0;
            else iro[i][0]=255;
            if(i%4==0||i%4==1)iro[i][1]=0;
            else iro[i][1]=255;
            if(i<4)iro[i][2]=0;
            else iro[i][2]=255;
        }
        vector<string> ironame={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
        int ans=-1;
        long long mdist=numeric_limits<int>::max();
        for (int i = 0; i < 8; ++i) {
            long long td=0;
            td+=(r-iro[i][2])*(r-iro[i][2]);
            td+=(g-iro[i][1])*(g-iro[i][1]);
            td+=(b-iro[i][0])*(b-iro[i][0]);
            if(td<mdist){
                ans=i;
                mdist=td;
            }
        }
        cout<<ironame[ans]<<endl;
    }

    return 0;
}