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 <iomanip>
#include <algorithm>
#include <cmath>

using namespace std;

struct Color{
	double r,g,b;
};

double sq( double a ){
	return a * a;
}

int main(int argc, char const* argv[])
{
	const char *color[] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};
	Color colorStrong[] = {{0,0,0},{0,0,255},{0,255,0},{0,255,255},{255,0,0},{255,0,255},{255,255,0},{255,255,255}};

	Color inputColor;
	int rgb;
	double d[8];
	char damy;

	while( cin >> damy && damy != '0' ){
		cin >> hex >> rgb;
		inputColor.r = rgb >> 16;
		inputColor.g = ( rgb >> 8 ) & 0xff;
		inputColor.b = rgb & 0xff;

		for( int i = 0;i < 8;i++ ){
			d[i] = sqrt( sq( inputColor.r - colorStrong[i].r ) + sq( inputColor.g - colorStrong[i].g ) + sq( inputColor.b - colorStrong[i].b ) );
		}

		double* answer = min_element( d, d + 8 );

		for( int i = 0;i < 8;i++ ){
			if( answer == &d[i] ){
				cout << color[i] << endl;
				break;
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

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

int main()
{
	int color[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 name[8]={
		"black",
		"blue",
		"lime",
		"aqua",
		"red",
		"fuchsia",
		"yellow",
		"white"
	};
	
	for(string s;cin>>s,s[0]!='0';){
		s=s.substr(1);
		int c[3];
		rep(i,3)
			c[i]=htoi(s[i*2])*16+htoi(s[i*2+1]);
		
		int res=0;
		rep(i,8){
			int ci=(c[0]-color[i][0])*(c[0]-color[i][0])+(c[1]-color[i][1])*(c[1]-color[i][1])+(c[2]-color[i][2])*(c[2]-color[i][2]);
			int cr=(c[0]-color[res][0])*(c[0]-color[res][0])+(c[1]-color[res][1])*(c[1]-color[res][1])+(c[2]-color[res][2])*(c[2]-color[res][2]);
			if(cr>ci)
				res=i;
		}
		cout<<name[res]<<endl;
	}
	
	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
 
const int INF = 10000000;
 
int base16(char c) {
  if( 'a' <= c ) return c-'a'+10;
  else return c-'0';
}
 
int main() {
 
  string s;
 
  int coltabel[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 nametable[8] = { "black", "blue", "lime", "aqua",
             "red", "fuchsia", "yellow", "white" };
 
  while(true) {
 
    cin>>s;
    if( s=="0" ) break;
 
    int r,g,b;
    r = base16(s[1])*16+base16(s[2]);
    g = base16(s[3])*16+base16(s[4]);
    b = base16(s[5])*16+base16(s[6]);
 
    int res,tmp=INF,t;
 
    for(int i=0; i<8; i++) {
      if( ( t = (r-coltabel[i][0])*(r-coltabel[i][0])
      + (g-coltabel[i][1])*(g-coltabel[i][1])
      + (b-coltabel[i][2])*(b-coltabel[i][2]) )
      < tmp ) {
    //cout<<t<<" "<<i<<endl;
    res = i;
    tmp = t;
      }
    }
 
    cout<<nametable[res]<<endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    string color[]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
    int colornum[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 value[200]={};
    for(int i=0;i<10;i++)value['0'+i]=i;
    for(int i=0;i<6;i++)value['a'+i]=10+i;
    string str;
    while(cin>>str&&str!="0"){
        int num[3];
        for(int i=0;i<3;i++)num[i]=value[str[1+2*i]]*16+value[str[2+2*i]];
        int ans[8]={};
        for(int i=0;i<8;i++)
            for(int j=0;j<3;j++)
                ans[i]+=pow(colornum[i][j]-num[j],2);
        int co=0;
        for(int i=1;i<8;i++)if(ans[co]>ans[i])co=i;
        cout<<color[co]<<endl;
    }
}

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

string color[8] = {
	"black","blue","lime","aqua","red","fuchsia","yellow","white"
};
int dr[8] = {0,0,0,0,255,255,255,255};
int dg[8] = {0,0,255,255,0,0,255,255};
int db[8] = {0,255,0,255,0,255,0,255};

int to_i(string s){
	int n=0;

	if( s[0] >= '0' && s[0] <= '9' ){
		n += (s[0]-'0')*16;
	}else{
		n += (s[0]-'a'+10)*16;
	}
	if( s[1] >= '0' && s[1] <= '9' ){
		n += s[1] - '0';
	}else{
		n += s[1] - 'a' + 10;
	}
	return n;
}

vector<int> to_RGB(string s){
	vector<int> c;
	c.push_back( to_i( s.substr(1,2) ) );
	c.push_back( to_i( s.substr(3,4) ) );
	c.push_back( to_i( s.substr(5,6) ) );
	return c;
}

int d(int r,int rk,int g,int gk,int b,int bk){
	return (r-rk)*(r-rk) + (g-gk)*(g-gk) + (b-bk)*(b-bk);
}

int main(){
	string s;
	while( cin >> s , s != "0" ){
		vector<int> c = to_RGB( s );
		int ans = 200000;

		for(int i=0 ; i < 8 ; i++ ){
			int dk = d( c[0] , dr[i] , c[1] , dg[i] , c[2] , db[i] );
			ans = min( ans , dk );
		}
		for(int i=0 ; i < 8 ; i++ ){
			int dk = d( c[0] , dr[i] , c[1] , dg[i] , c[2] , db[i] );
			if( dk == ans ){
				cout << color[i] << endl;
				break;
			}
		}
	}
}