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<string>
#include<cmath>

using namespace std;

void DevideColor(string, int&, int&, int&);
int Atoi16(char);
double Calculate(int, int, int, int, int, int);

int main(){
  int i, Red, Green, Blue;
  double min, font[8];
  string Color, StrongColor;
  string color[8] = {"black", "blue", "lime", "aqua", "red", "fuchsia","yellow", "white"};

  while(1){
    cin >> Color;
    if(Color == "0") break;

    DevideColor(Color, Red, Green, Blue);

    font[0] = Calculate(Red, Green, Blue, 0, 0, 0);
    font[1] = Calculate(Red, Green, Blue, 0, 0, 255);
    font[2] = Calculate(Red, Green, Blue, 0, 255, 0);
    font[3] = Calculate(Red, Green, Blue, 0, 255, 255);
    font[4] = Calculate(Red, Green, Blue, 255, 0, 0);
    font[5] = Calculate(Red, Green, Blue, 255, 0, 255);
    font[6] = Calculate(Red, Green, Blue, 255, 255, 0);
    font[7] = Calculate(Red, Green, Blue, 255, 255, 255);

    min = font[0];
    StrongColor = color[0];

    for(i=1; i<8; ++i){
      if(font[i] < min){
        min = font[i];
        StrongColor = color[i];
      }
    }

    cout << StrongColor << endl;
  }

  return 0;

}

void DevideColor(string s, int& r, int& g, int& b){
  string R, G, B;
  copy(s.begin()+1, s.begin()+3, back_inserter(R));
  copy(s.begin()+3, s.begin()+5, back_inserter(G));
  copy(s.begin()+5, s.end(), back_inserter(B));
  r = Atoi16(R[0])*16 + Atoi16(R[1]);
  g = Atoi16(G[0])*16 + Atoi16(G[1]);
  b = Atoi16(B[0])*16 + Atoi16(B[1]);
}

int Atoi16(char c){
  int x;
  if(c >= '0' && c <= '9')
    x = c - 48;
  else
    x = c - 87;
  return x;
}

double Calculate(int r, int g, int b, int _r, int _g, int _b){
  int R, G, B;
  R = r - _r;
  G = g - _g;
  B = b - _b;
  return sqrt(R*R + G*G + B*B);
}

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

using namespace std;

int colorCalc(char c1, char c2)
{
	int color = 0;
	if('a' <= c1 && c1 <= 'f')
	{
		color += (c1 - 'a' + 10) * 16;
	}
	else
	{
		color += (c1 - '0') * 16;
	}
	if('a' <= c2 && c2 <= 'f')
	{
		color += c2 - 'a' + 10;
	}
	else
	{
		color += c2 - '0';
	}
	return(color);
}
void solve()
{
	int colors[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"};
	string str;
	while(cin >> str, str != "0")
	{
		int r = colorCalc(str[1], str[2]);
		int g = colorCalc(str[3], str[4]);
		int b = colorCalc(str[5], str[6]);
		int min = 999999999;
		int label = 0;
		for(int i = 0; i < 8; ++i)
		{
			int sum = sqrt((double)(r - colors[i][0]) * (r - colors[i][0]) + (g - colors[i][1]) * (g - colors[i][1]) + (b - colors[i][2]) * (b - colors[i][2]));
			if(sum < min)
			{
				min = sum;
				label = i;
			}
		}
		cout << name[label] << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

using namespace std;

int colorCalc(char c1, char c2)
{
	int color = 0;
	if('a' <= c1 && c1 <= 'f')
	{
		color += (c1 - 'a' + 10) * 16;
	}
	else
	{
		color += (c1 - '0') * 16;
	}
	if('a' <= c2 && c2 <= 'f')
	{
		color += c2 - 'a' + 10;
	}
	else
	{
		color += c2 - '0';
	}
	return(color);
}
void solve()
{
	int colors[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"};
	string str;
	while(cin >> str, str != "0")
	{
		int r = colorCalc(str[1], str[2]);
		int g = colorCalc(str[3], str[4]);
		int b = colorCalc(str[5], str[6]);
		int min = 999999999;
		int label = 0;
		for(int i = 0; i < 8; ++i)
		{
			int sum = sqrt((double)(r - colors[i][0]) * (r - colors[i][0]) + (g - colors[i][1]) * (g - colors[i][1]) + (b - colors[i][2]) * (b - colors[i][2]));
			if(sum < min)
			{
				min = sum;
				label = i;
			}
		}
		cout << name[label] << endl;
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <tuple>

int tsurai(int r, int g, int b) {
  return r*r + g*g + b*b;
}

int testcase_ends() {
  char c;
  scanf(" %c", &c);
  if (c == '0') return 1;

  int r, g, b;
  scanf("%2x%2x%2x", &r, &g, &b);

  std::vector<std::pair<std::string, std::tuple<int, int, int>>> col;
  int f = 255;
  
  col.emplace_back("black", std::make_tuple(0, 0, 0));
  col.emplace_back("blue", std::make_tuple(0, 0, f));
  col.emplace_back("lime", std::make_tuple(0, f, 0));
  col.emplace_back("aqua", std::make_tuple(0, f, f));
  col.emplace_back("red", std::make_tuple(f, 0, 0));
  col.emplace_back("fuchsia", std::make_tuple(f, 0, f));
  col.emplace_back("yellow", std::make_tuple(f, f, 0));
  col.emplace_back("white", std::make_tuple(f, f, f));

  int d = 1e9;
  std::string res;
  for (auto const& p: col) {
    std::string cur;
    std::tuple<int, int, int> rgb;
    std::tie(cur, rgb) = p;
    int r0, g0, b0;
    std::tie(r0, g0, b0) = rgb;

    int cur_d = tsurai(r0-r, g0-g, b0-b);
    if (d > cur_d) {
      d = cur_d;
      res = cur;
    }
  }
  printf("%s\n", res.c_str());
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}