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 <cstdio>
#include <cmath>
using namespace std;
int num[1000];
const string ans[] = {"black","blue","lime","aqua","red",
		      "fuchsia","yellow","white"};
int ff = 15*16 + 15;
int RGB[][3] = {{0,0,0},
		{0,0,ff},
		{0,ff,0},
		{0,ff,ff},
		{ff,0,0},
		{ff,0,ff},
		{ff,ff,0},
		{ff,ff,ff}};

int _16to10(string a){
  return num[a[0]] * 16 + num[a[1]];
}
int main(){
  num['1'] = 1,  num['2'] = 2,  num['3'] = 3,  num['4'] = 4,num['5'] = 5,num['6'] = 6,num['7'] = 7,num['8'] = 8,num['9'] = 9,num['a'] = 10,num['b'] = 11,  num['c'] = 12,  num['d'] = 13,  num['e'] = 14,num['f'] = 15;
  string color;
  while(cin >> color,color[0] !='0') {
    string r,g,b;
    r = color.substr(1,2);
    g = color.substr(3,2);
    b = color.substr(5,2);
    int rnum,gnum,bnum;
    rnum = _16to10(r);
    gnum = _16to10(g);
    bnum = _16to10(b);
    double mn = 1000000000;
    string anscolor;
    for(int i = 7 ; i >= 0 ; i-- ){
      double dk = pow(rnum-RGB[i][0],2)+pow(gnum-RGB[i][1],2)+pow(bnum-RGB[i][2],2);
      if(mn >= dk){
	mn = dk;
	anscolor = ans[i];
      }
    } 
    cout << anscolor << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rrep(i,n) for(int i=(int)(n)-1; i>=0; i--)
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define pr(a) cout << (a) << endl
#define PR(a,b) cout << (a) << " " << (b) << endl
#define F first
#define S second
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000001;
const ll MAXL=1000000000000000001LL;
const ll mod=1000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

double x(string s) {
  double a=1,ans=0;
  rrep(i,2) {
    if(isdigit(s[i])) ans+=(int)(s[i]-'0')*a;
    else ans+=((int)(s[i]-'a')+10)*a;
    a*=16;
  }
  return ans;
}

int main() {
  double 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}};
  string c[8]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
  string s;
  while(cin >> s && s!="0") {
    int ans=0;
    double min=MAX;
    double z[3];
    s=s.substr(1);
    rep(i,3) z[i]=x(s.substr(i*2,2));
    rep(i,8) {
      double v=sqrt((z[0]-d[i][0])*(z[0]-d[i][0])+(z[1]-d[i][1])*(z[1]-d[i][1])+(z[2]-d[i][2])*(z[2]-d[i][2]));
      if(v<min) {
	ans=i;
	min=v;
      }
    }
    pr(c[ans]);
  }
  return 0;
}

C++: #include<cstdio>

using namespace std;

int main(){
	char *color[]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
	int rgb[][3]={{0x00,0x00,0x00},
				  {0x00,0x00,0xff},
				  {0x00,0xff,0x00},
				  {0x00,0xff,0xff},
				  {0xff,0x00,0x00},
				  {0xff,0x00,0xff},
				  {0xff,0xff,0x00},
				  {0xff,0xff,0xff}};

	for(char sam[8];scanf("%s",sam),sam[0]-'0';){
		int b;	sscanf(sam+5,"%x",&b);	sam[5]='\0';
		int g;	sscanf(sam+3,"%x",&g);	sam[3]='\0';
		int r;	sscanf(sam+1,"%x",&r);
		int dmin=1000000,imin;
		for(int i=0;i<8;i++){
			int dis=(r-rgb[i][0])*(r-rgb[i][0])+(g-rgb[i][1])*(g-rgb[i][1])+(b-rgb[i][2])*(b-rgb[i][2]);
			if(dis<dmin)	dmin=dis,imin=i;
		}
		puts(color[imin]);
	}

	return 0;
}

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

int hexToDec(char x){
    if('0' <= x && x <= '9'){
        return x-'0';
    }else{
        return 10 + (x - 'a');
    }
}

int data[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 color[8] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};

int main(){
    while(1){
        string s;
        cin >> s;

        if(s == "0")    break;
    
        int r, g, b;
        r = 16 * hexToDec(s[1]) + hexToDec(s[2]);
        g = 16 * hexToDec(s[3]) + hexToDec(s[4]);
        b = 16 * hexToDec(s[5]) + hexToDec(s[6]);

        double dist = DBL_MAX;
        int ans;

        for(int i = 0; i < 8; i++){
            double tmp = sqrt(pow(r - data[i][0], 2.0) + pow(g - data[i][1], 2.0) + pow(b - data[i][2], 2.0));
            if(tmp < dist){
                dist = tmp;
                ans = i;
            }
        }

        cout << color[ans] << endl;
    }

    return 0;
}#include<iostream>
#include<cfloat>
#include<cmath>
using namespace std;

int hexToDec(char x){
    if('0' <= x && x <= '9'){
        return x-'0';
    }else{
        return 10 + (x - 'a');
    }
}

int data[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 color[8] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};

int main(){
    while(1){
        string s;
        cin >> s;

        if(s == "0")    break;
    
        int r, g, b;
        r = 16 * hexToDec(s[1]) + hexToDec(s[2]);
        g = 16 * hexToDec(s[3]) + hexToDec(s[4]);
        b = 16 * hexToDec(s[5]) + hexToDec(s[6]);

        double dist = DBL_MAX;
        int ans;

        for(int i = 0; i < 8; i++){
            double tmp = sqrt(pow(r - data[i][0], 2.0) + pow(g - data[i][1], 2.0) + pow(b - data[i][2], 2.0));
            if(tmp < dist){
                dist = tmp;
                ans = i;
            }
        }

        cout << color[ans] << endl;
    }

    return 0;
}