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>

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 <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;

int main(){
	int r,g,b,n[6],p[8],q[8];
	char a[7];
	
	while(1){
		gets(a);
		if(a[0]=='0'){
			return 0;
		}
		for(int i=1;i<7;i++){
			if(a[i]=='0'){
				n[i-1]=0;
			}
			if(a[i]=='1'){
				n[i-1]=1;
			}
			if(a[i]=='2'){
				n[i-1]=2;
			}
			if(a[i]=='3'){
				n[i-1]=3;
			}
			if(a[i]=='4'){
				n[i-1]=4;
			}
			if(a[i]=='5'){
				n[i-1]=5;
			}
			if(a[i]=='6'){
				n[i-1]=6;
			}
			if(a[i]=='7'){
				n[i-1]=7;
			}
			if(a[i]=='8'){
				n[i-1]=8;
			}
			if(a[i]=='9'){
				n[i-1]=9;
			}
			if(a[i]=='a'){
				n[i-1]=10;
			}
			if(a[i]=='b'){
				n[i-1]=11;
			}
			if(a[i]=='c'){
				n[i-1]=12;
			}
			if(a[i]=='d'){
				n[i-1]=13;
			}
			if(a[i]=='e'){
				n[i-1]=14;
			}
			if(a[i]=='f'){
				n[i-1]=15;
			}
		}
		r=n[0]*16+n[1];
		g=n[2]*16+n[3];
		b=n[4]*16+n[5];
		
		p[0]=r*r+g*g+b*b;
		p[1]=r*r+g*g+(255-b)*(255-b);
		p[2]=r*r+(255-g)*(255-g)+b*b;
		p[3]=r*r+(255-g)*(255-g)+(255-b)*(255-b);
		p[4]=(255-r)*(255-r)+g*g+b*b;
		p[5]=(255-r)*(255-r)+g*g+(255-b)*(255-b);
		p[6]=(255-r)*(255-r)+(255-g)*(255-g)+b*b;
		p[7]=(255-r)*(255-r)+(255-g)*(255-g)+(255-b)*(255-b);
		
		for(int i=0;i<8;i++){
			q[i]=i;
		}
		for(int i=1;i<8;i++){
			for(int j=0;j<8-i;j++){
				if(p[j]>p[j+1]){
					r=p[j]; p[j]=p[j+1]; p[j+1]=r;
					b=q[j]; q[j]=q[j+1]; q[j+1]=b;
				}
			}
		}
		
		if(q[0]==0){
			cout << "black\n";
		}
		if(q[0]==1){
			cout << "blue\n";
		}
		if(q[0]==2){
			cout << "lime\n";
		}
		if(q[0]==3){
			cout << "aqua\n";
		}
		if(q[0]==4){
			cout << "red\n";
		}
		if(q[0]==5){
			cout << "fuchsia\n";
		}
		if(q[0]==6){
			cout << "yellow\n";
		}
		if(q[0]==7){
			cout << "white\n";
		}
	}
	
return 0;
}

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

template<class T>
T sqr(T obj) {return obj * obj;}

struct color {
	string name;
	int R, G, B;

	color(string n, int r, int g, int b) {
		name = n;
		R = r;
		G = g;
		B = b;
	}
};

color color_list[] = {
	color("black", 0x00, 0x00, 0x00),
	color("blue", 0x00, 0x00, 0xff),
	color("lime", 0x00, 0xff, 0x00),
	color("aqua", 0x00, 0xff, 0xff),
	color("red", 0xff, 0x00, 0x00),
	color("fuchsia", 0xff, 0x00, 0xff),
	color("yellow", 0xff, 0xff, 0x00),
	color("white", 0xff, 0xff, 0xff),
};

int main() {
	string s;
	while(cin >> s) {
		if(s[0] == '0')
			break;

		int mind, indx;
		indx = 0;
		mind = 1e8;

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

			if('0' <= s[2 + 2 * j] && s[2 + 2 * j] <= '9')
				tmp += (s[2 + 2 * j] - '0');
			else
				tmp += (s[2 + 2 * j] - 'a' + 10);
			a[j] = tmp;
		}

		for(int i = 0; i < 8; i++) {
			int d = 0;

			d += sqr(color_list[i].R - a[0]);
			d += sqr(color_list[i].G - a[1]);
			d += sqr(color_list[i].B - a[2]);
			if(d < mind) {
				indx = i;
				mind = d;
			}
		}
		cout << color_list[indx].name << endl;
	}
}

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

int main(){
  string s;
  int color[][3] = {
                    {0, 0, 0}, //black
                    {0, 0, 0xff}, //blue
                    {0, 0xff, 0}, //lime
                    {0, 0xff, 0xff}, //aqua
                    {0xff, 0, 0}, //red
                    {0xff, 0, 0xff}, //fuchsia
                    {0xff, 0xff, 0}, //yellow
                    {0xff, 0xff, 0xff} //white
  };
  string ans[] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
  while(std::cin >> s, s != "0"){
    double min_val = 1e9;
    int num = -1;
    for (int i = 0; i < 8; i++) {
      double val = 0;
      unsigned int tmp;
      string type;
      // type = "0x" + s.substr(1, 2);
      type = s.substr(1, 2);
      // std::cout << type << std::endl;
      // sscanf("0x" + s.substr(), "%x", tmp);
      sscanf(type.c_str(), "%x", &tmp);
      // std::cout << type << std::endl;
      val += (color[i][0] - tmp)*(color[i][0] - tmp);
      
      type = "0x" + s.substr(3, 2);
      sscanf(type.c_str(), "%x", &tmp);
      val += (color[i][1] - tmp)*(color[i][1] - tmp);
      
      type = "0x" + s.substr(5, 2);
      sscanf(type.c_str(), "%x", &tmp);
      val += (color[i][2] - tmp)*(color[i][2] - tmp);
      if(min_val > val){
        min_val = val;
        num = i;
      }
    }
    std::cout << ans[num] << std::endl;
  }
  return 0;
}