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<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<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,256},
  {  0,256,  0},
  {  0,256,256},
  {256,  0,  0},
  {256,  0,256},
  {256,256,  0},
  {256,256,256}
};
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 <vector>
#include <climits>
using namespace std;

struct Color {
    string name; int r, g, b;
};
vector<Color> colors = {
    (Color){"black", 0, 0, 0},
    (Color){"blue", 0, 0, 255},
    (Color){"lime", 0, 255, 0},
    (Color){"aqua", 0, 255, 255},
    (Color){"red", 255, 0, 0},
    (Color){"fuchsia", 255, 0, 255},
    (Color){"yellow", 255, 255, 0},
    (Color){"white", 255, 255, 255}
};

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

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

int main() {
    string s;
    while (cin >> s, s != "0") {
        int r = dec(s[1]) * 16 + dec(s[2]);
        int g = dec(s[3]) * 16 + dec(s[4]);
        int b = dec(s[5]) * 16 + dec(s[6]);
        int mn = INT_MAX, k = -1;
        for (int i=0; i<(int)colors.size(); ++i) {
            int t = sq(r-colors[i].r) + sq(g-colors[i].g) + sq(b-colors[i].b);
            if (t < mn) {
                mn = t;
                k = i;
            }
        }
        cout << colors[k].name << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int FF = 255, F  = 16;

string name[] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "while"};
int R[] = { 0, 0, 0, 0, FF, FF, FF, FF};
int G[] = { 0, 0, FF, FF, 0, 0, FF, FF};
int B[] = { 0, FF, 0, FF, 0, FF, 0, FF};

int num(char t)
{
    if(t >='0' && t <= '9') return t - '0';
    else return t - 'a' + 10;
}
int f(int n) { return n * n;}

int main()
{
    string s;
    while(cin >> s)
    {
        if(s == "0") break;

        int mind = FF * FF * F, d = 0, ans = 0;
        REP(8)
        {
            d = f(R[i] -( num(s[1]) * F + num(s[2]) )) + f(G[i]-(num(s[3])*F + num(s[4]))) + f(B[i] - (num(s[5])*F + num(s[6])));
            if(mind > d) { ans = i; mind = d;}
        }
        cout << name[ans] << 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 a[8][3]={
  {  0,  0,  0},
  {  0,  0,256},
  {  0,256,  0},
  {  0,256,256},
  {256,  0,  0},
  {256,  0,256},
  {256,256,  0},
  {256,256,256}
};
string out[8]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
int main(){
  string in;
  while(cin>>in,in!="0"){
    int min=1e9;
    int mini=1e9;
    loop(i,1,7)in[i]-='0';
    int b[3]={in[1]*16+in[2],in[3]*16+in[4],in[5]*16+in[6]};
    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;
  }
}