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{
  int 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[8] = {"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;
  COL col[8];
  
  while (scanf("%1s", &sh), sh != '0'){
    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 <bits/stdc++.h>

using namespace std;

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

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

int main() {
	int len, d, j, minD, index;
	int rgb[3];
	string colorInfo, tmp;
	stringstream ss;

	while (cin >> colorInfo, colorInfo[0] == '#') {
		len = colorInfo.size() - 1;

		for (int i = 1, j = 0; i < len; i += 2) {
			ss.clear();
			ss.str("");

			ss << colorInfo[i] << colorInfo[i + 1];
			ss >> tmp;
			//cout << tmp << endl;
			rgb[j++] = strtol(tmp.c_str(), 0, 16);
		}

		minD = INT_MAX;
		for (j = 0; j < 8; j++) {
			d = pow(rgb[0] - RGB[j][0], 2) + pow(rgb[1] - RGB[j][1], 2) + pow(rgb[2] - RGB[j][2], 2);
			if (d < minD) {
				minD = d;
				index = j;
			}
		}

		cout << COLOR[index] << endl;

	}

	return 0;
}

C++: #include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int ff=255;
int conv(char *str){
    int ret=0;
    for(int i=0;i<2;i++){
        int val;
        if(str[i]>='0'&&str[i]<='9')val=str[i]-'0';
        else val=str[i]-'a'+10;
        ret=(ret<<4)+val;
    }
    return ret;
}
int main(){
    char *Name[8]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
    int rgb[3][8]={{0,0,0,0,ff,ff,ff,ff},{0,0,ff,ff,0,0,ff,ff},{0,ff,0,ff,0,ff,0,ff}};
    char str[100];
    while(scanf("%s",str),str[0]!='0'){
        int rgb_[3];
        for(int i=0;i<3;i++){
            rgb_[i]=conv(str+1+i*2);
        }
        int mav,mac=1e9;
        for(int i=0;i<8;i++){
            int val=0;
            for(int j=0;j<3;j++)val+=(rgb_[j]-rgb[j][i])*(rgb_[j]-rgb[j][i]);
            if(mac>val){
                mac=val;
                mav=i;
            }
        }
        printf("%s\n",Name[mav]);

    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

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

int dis(int id, vector<int> a){
  int res = 0;
  for(int i=0;i<3;i++){
    int comp = 0;
    if(id&1) comp = 255;
    res += (a[i]-comp)*(a[i]-comp);
    id/=2;
  }
  return res;
}

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

int main(){
  string s;
  while(cin >> s, s != "0"){
    vector<int> a(3);
    for(int i=0;i<3;i++){
      a[i] = toDec(s[2*i+1])*16 + toDec(s[2*i+2]);
    }
    reverse(a.begin(), a.end());
    int ans = 0, dmin = dis(0,a);
    for(int i=1;i<8;i++){
      if(dis(i,a) < dmin){
        ans = i; dmin = dis(i,a);
      }
    }
    cout << colors[ans] << endl;
  }
}

C++: #include<iostream>
#include<string>
#include<cstring>
#include<cctype>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define INF 1e6
using namespace std;

int d(string s,int color[3]){
  int red=0,blue=0,green=0;
  if(!isdigit(s[1]))red+=(s[1]-'a'+10)*16;
  else red+=(s[1]-'0')*16;
  if(!isdigit(s[2]))red+=(s[2]-'a'+10);
  else red+=(s[2]-'0');
  if(!isdigit(s[3]))green+=(s[3]-'a'+10)*16;
  else green+=(s[3]-'0')*16;
  if(!isdigit(s[4]))green+=(s[4]-'a'+10);
  else green+=(s[4]-'0');
  if(!isdigit(s[5]))blue+=(s[5]-'a'+10)*16;
  else blue+=(s[5]-'0')*16;
  if(!isdigit(s[6]))blue+=(s[6]-'a'+10);
  else blue+=(s[6]-'0');   
  return sqrt(pow((red-color[0]),2)+pow((green-color[1]),2)+pow((blue-color[2]),2));
}

int cl[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 main(){
  string str;
  while(1){
    cin>>str;
    if(str=="0")break;
    int num=INF;
    string ans="";
    rep(i,8){
      if(num>d(str,cl[i])){
	if(i==0)ans="black";
	else if(i==1)ans="blue";
	else if(i==2)ans="lime";
	else if(i==3)ans="aqua";
	else if(i==4)ans="red";
	else if(i==5)ans="fuchsia";
	else if(i==6)ans="yellow";
	else if(i==7)ans="white";
	num=d(str,cl[i]);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}