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 rep(i,n) for(int i = 0; i < (int)(n); i++)

int code[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"
};

int convert(string s){
    int d;
    sscanf(s.c_str(), "%x", &d);
    return d;
}

int main(){
    string line;
    while(cin >> line && line[0] != '0'){
        int r = convert(line.substr(1, 2));
        int g = convert(line.substr(3, 2));
        int b = convert(line.substr(5, 2));
        int ans_dist = 1e9;
        string ans = "--";
        rep(i,8){
            auto c = code[i];
            int d = 0;
            d += (r-c[0]) * (r-c[0]);
            d += (g-c[1]) * (g-c[1]);
            d += (b-c[2]) * (b-c[2]);
            if(d < ans_dist){
                ans_dist = d;
                ans = name[i];
            }
        }
        cout << ans << endl;
    }
}

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

map<char,int> f;

void foo(){
	for(int i=0 ; i<16 ; ++i ){
		if( i < 10 )
			f[(char)(i+'0')] = i;
		else
			f[(char)(i-10+'a')] = i;
	}
}

int to_i(char c1,char c2){
	return f[c1]*16+f[c2];
}

vector<int> solve(string s){
	int R = to_i( s[1] , s[2] );
	int G = to_i( s[3] , s[4] );
	int B = to_i( s[5] , s[6] );
	vector<int> color;
	color.push_back( R );
	color.push_back( G );
	color.push_back( B );
	return color;
}

int main(){
	const int t[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 colorName[8] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};
	foo();

	string s;
	while( cin >> s , s != "0" ){
		vector<int> color = solve( s );
		int Rk = color[0];
		int Gk = color[1];
		int Bk = color[2];
		int ans = 0;
		int dk = 255*3+1;
		//cout << "R:" << Rk << " G:" << Gk << " B:" << Bk << endl;
		
		for(int i=0 ; i<8 ; ++i ){
			int R = t[i][0];
			int G = t[i][1];
			int B = t[i][2];
			dk = min( abs(Rk-R)+abs(Gk-G)+abs(Bk-B) , dk );
		}

		for(int i=0 ; i<8 ; ++i ){
			int R = t[i][0];
			int G = t[i][1];
			int B = t[i][2];
			if( abs(Rk-R)+abs(Gk-G)+abs(Bk-B) == dk ){
				ans = i;
				break;
			}
		}
		cout << colorName[ ans ] << endl;
	}
}

C++: #include <iostream>
#include <string>
#include <cctype>

using namespace std;

int pow(int x, int n) {
  int ans = 1;
  for(int i = 0; i < n; i++) {
    ans *= x;
  }
  return ans;
}

int charToInt(char c) {
  return (int)c - (int)'0';
}

int _16to10(char c) {
  int ans = charToInt(c);
  if(ans >= 0 && ans <= 9) return ans;
  else return (int)tolower(c) - (int)'a' + 10;
}

int _16to10(string str) {
  int ans = 0;
  for(int i = 0; i < str.length(); i++) {
    ans += _16to10(str[i])*pow(16, str.length()-i-1);
  }
  return ans;
}

int d2(string a, string b) {
  int ans = 0;
  for(int i = 0; i < 3; i++) {
    int p = i*2;
    ans += pow(_16to10(a.substr(p,2))-_16to10(b.substr(p,2)), 2);
  }
  return ans;
}

int main() {
  string colors[8][2] = {{"black", "000000"},
			 {"blue", "0000ff"},
			 {"lime", "00ff00"},
			 {"aqua", "00ffff"},
			 {"red", "ff0000"},
			 {"fuchsia", "ff00ff"},
			 {"yellow", "ffff00"},
			 {"white", "ffffff"}};
  while(1) {
    string str;
    cin >> str;
    if(str == "0") break;

    int min = 999999;
    int k;
    for(int i = 0; i < 8; i++) {
      int temp = d2(str.substr(1, 6), colors[i][1]);
      if(temp < min) {
	min = temp;
	k = i;
      }
    }
    cout << colors[k][0] << endl;
  }
  return 0;
}

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

int R,G,B;
void solve() {
  string color[8] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};
  int icolor[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 nearest=0,dist,mindist=1000000;
  for(int i=0;i<8;i++) {
    dist = sqrt( (R-icolor[i][0])*(R-icolor[i][0]) + (G-icolor[i][1])*(G-icolor[i][1]) + (B-icolor[i][2])*(B-icolor[i][2]));
    if(dist < mindist) {
      mindist = dist;
      nearest = i;
    }
  }
  cout << color[nearest] << endl;
}

int main() {
  string str;
  while(getline(cin,str)) {
    if(str == "0") break;
    R = strtol(str.substr(1,2).c_str(),NULL,16);
    G = strtol(str.substr(3,2).c_str(),NULL,16);
    B = strtol(str.substr(5,2).c_str(),NULL,16);
    solve();
  }
}