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 <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    string color[] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};

    for(;;){
        string s;
        cin >> s;
        if(s == "0")
            return 0;

        int a[3] = {0};
        for(int i=0; i<6; ++i){
            a[i/2] *= 16;
            if('0' <= s[i+1] && s[i+1] <= '9')
                a[i/2] += s[i+1] - '0';
            else
                a[i/2] += s[i+1] - 'a' + 10;
        }

        int k;
        int minD = INT_MAX;
        for(int i=0; i<8; ++i){
            int d = 0;
            for(int j=0; j<3; ++j){
                if(i & (1<<(2-j)))
                    d += (255 - a[j]) * (255 - a[j]);
                else
                    d += a[j] * a[j];
            }
            if(d < minD){
                minD = d;
                k = i;
            }
        }

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

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

class Col
{
public:
  int R,G,B;
  Col():R(0),G(0),B(0){}
  Col(int R,int G,int B):R(R),G(G),B(B){}
};

int _16to10(string s)
{
  int a[2];
  for(int i=0;i<2;i++)
    {
      if(s[i] == 'a')
	a[i] = 10;
      else if(s[i] == 'b')
	a[i] = 11;
      else if(s[i] == 'c')
	a[i] = 12;
      else if(s[i] == 'd')
	a[i] = 13;
      else if(s[i] == 'e')
	a[i] = 14;
      else if(s[i] == 'f')
	a[i] = 15;
      else 
	a[i] = s[i] - '0';
    }
  return a[1]+a[0]*16;
}

int main()
{
  string s;
  vector<Col> vec;
  vector<string> name;
  vec.resize(8),name.resize(8);
  int ff = _16to10("ff");
  vec[0] = Col(0,0,0);
  vec[1] = Col(0,0,ff);
  vec[2] = Col(0,ff,0);
  vec[3] = Col(0,ff,ff);
  vec[4] = Col(ff,0,0);
  vec[5] = Col(ff,0,ff);
  vec[6] = Col(ff,ff,0);
  vec[7] = Col(ff,ff,ff);
  name[0] = "black";
  name[1] = "blue";
  name[2] = "lime";
  name[3] = "aqua";
  name[4] = "red";
  name[5] = "fuchsia";
  name[6] = "yellow";
  name[7] = "white";
  while(true)
    {
      cin >> s;
      cerr << s << endl;
      if(s == "0")
	break;
      int R,G,B;
      R = _16to10(s.substr(1,2));
      G = _16to10(s.substr(3,2));
      B = _16to10(s.substr(5,2));

      int men = (1<<28),pos = -1;
      for(int i=0;i<8;i++)
	{
	  int d =  sqrt(pow(R-vec[i].R,2)+pow(B-vec[i].B,2)+pow(G-vec[i].G,2));
	  if(men > d)
	    {
	      men = d;
	      pos = i;
	    }
	}
      cout << name[pos] << endl;

    }
  return 0;
}

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

struct set{
  string val;
  double rgb[3];
};

set temp[8];

string name[8] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};
void make_temp(){
  for(int i=0;i<8;i++){
    temp[i].val = name[i];
    temp[i].rgb[0] = (i >> 2 & 1 ? 255 : 0);
    temp[i].rgb[1] = (i >> 1 & 1 ? 255 : 0);
    temp[i].rgb[2] = (i & 1 ? 255 : 0);
  }
}

int main(){
  make_temp();

  while(true){
    double num[3];
    double ans = (2 << 10);
    string s,spt[3];
    cin >> s;
    if(s == "0") break;

    s.erase(0,1);
    for(int i=0;i<3;i++){
      for(int j=0;j<2;j++){
	spt[i] += s[0]; s.erase(0,1);
      }

      int a;
      sscanf(spt[i].c_str(),"%x",&a);
      num[i] = a;
    }
    
    string a;
    for(int i=0;i<8;i++){
      double d = sqrt(pow(num[0] - temp[i].rgb[0],2) + pow(num[1] - temp[i].rgb[1],2) + pow(num[2] - temp[i].rgb[2],2));

      if(ans > d){
	a = temp[i].val; ans = d;
      }
    }
    cout << a << endl;
  }

}

C++: // Tazoe

#include <iostream>
#include <string>
using namespace std;

int main()
{
	while(true){
		string S;
		cin >> S;

		if(S=="0")
			break;

		if(S[1]>='0'&&S[1]<='7'){
			if(S[3]>='0'&&S[3]<='7'){
				if(S[5]>='0'&&S[5]<='7'){
					cout << "black" << '\n';
				}
				else{
					cout << "blue" << '\n';
				}
			}
			else{
				if(S[5]>='0'&&S[5]<='7'){
					cout << "lime" << '\n';
				}
				else{
					cout << "aqua" << '\n';
				}
			}
		}
		else{
			if(S[3]>='0'&&S[3]<='7'){
				if(S[5]>='0'&&S[5]<='7'){
					cout << "red" << '\n';
				}
				else{
					cout << "fuchsia" << '\n';
				}
			}
			else{
				if(S[5]>='0'&&S[5]<='7'){
					cout << "yellow" << '\n';
				}
				else{
					cout << "white" << '\n';
				}
			}
		}
	}

	return 0;
}