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++: (function(input) {
  var lines = input.split("\n");
  var colors = [
    ['black', 0x00, 0x00, 0x00],
    ['blue', 0x00, 0x00, 0xff],
    ['lime', 0x00, 0xff, 0x00],
    ['aqua', 0x00, 0xff, 0xff],
    ['red', 0xff, 0x00, 0x00],
    ['fuchsia', 0xff, 0x00, 0xff],
    ['yellow', 0xff, 0xff, 0x00],
    ['white', 0xff, 0xff, 0xff],
  ];
  for (var i = 0; i < lines.length; ++i) {
    if (lines[i][0] === '#') {
      var best_color;
      var min_d = 3 * 256 * 256 + 1;
      var r = parseInt(lines[i].substr(1, 2), 16);
      var g = parseInt(lines[i].substr(3, 2), 16);
      var b = parseInt(lines[i].substr(5, 2), 16);
      for (var j = 0; j < colors.length; ++j) {
        var d = Math.pow(r - colors[j][1], 2) + Math.pow(g - colors[j][2], 2) + Math.pow(b - colors[j][3], 2);
        if (d < min_d) {
          min_d = d;
          best_color = colors[j][0];
        }
      }
      console.log(best_color);
    }
  }
})(require('fs').readFileSync('/dev/stdin', 'utf8').trim());

C++: #include<iostream>
#include<string>
#include<cmath>
using namespace std;
#define N 8
string table[N] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
struct Color{ string R, G, B;};

Color colors[N];

int convert(string hex){
    int p = 1, sum = 0;
    for ( int i = hex.size()-1; i >= 0; i--, p *= 16 ){
	sum += p*((isdigit(hex[i]))?(hex[i]-'0'):(hex[i]-'a'+10));
    }
    return sum;
}

double getDistance(Color c1, Color c2){
    int dr = convert(c1.R) - convert(c2.R);
    int dg = convert(c1.G) - convert(c2.G);
    int db = convert(c1.B) - convert(c2.B);
    return sqrt(dr*dr + dg*dg + db*db);
}

main(){
    for ( int i = 0; i < N; i++ ) colors[i].R = colors[i].G = colors[i].B = "00";
    colors[1].B = "ff";
    colors[2].G = "ff";
    colors[3].B = "ff";
    colors[3].G = "ff";
    colors[4].R = "ff";
    colors[5].R = "ff";
    colors[5].B = "ff";
    colors[6].R = "ff";
    colors[6].G = "ff";
    colors[7].R = "ff";
    colors[7].G = "ff";
    colors[7].B = "ff";
    string hex;
    while( cin >> hex && hex != "0"){
	string ans = "";
	double sub = (1<<30);
	Color target;
	target.R = hex.substr(1, 2);
	target.G = hex.substr(3, 2);
	target.B = hex.substr(5, 2);
	for ( int i = 0; i < N; i++ ){
	    double d = getDistance(colors[i], target);
	    if ( d < sub ){
		sub = d;
		ans = table[i];
	    }
	}
	cout << ans << endl;
    }
}

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


int tmp[2] = {16,1};
string s[8] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};

int hoge[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 to_ten(string s){
  int ans=0;
  for(int i=0; i<2; i++){
    if(s[i] == 'a') ans += 10*tmp[i];
    else if(s[i] == 'b') ans += 11*tmp[i];
    else if(s[i] == 'c') ans += 12*tmp[i];
    else if(s[i] == 'd') ans += 13*tmp[i];
    else if(s[i] == 'e') ans += 14*tmp[i];
    else if(s[i] == 'f') ans += 15*tmp[i];
    else ans += stoi(s.substr(i,1))*tmp[i];
  }
  return ans;
}

double d(string r,string g,string b,int i){
  double ans = 0;
  ans += (to_ten(r) - hoge[i][0]) * (to_ten(r) - hoge[i][0]);
  ans += (to_ten(g) - hoge[i][1]) * (to_ten(g) - hoge[i][1]);
  ans += (to_ten(b) - hoge[i][2]) * (to_ten(b) - hoge[i][2]);
  return ans;
}

int main(){


  while(1){
    string in; cin >> in;
    if(in == "0") break;
    string r = in.substr(1,2);
    string g = in.substr(3,2);
    string b = in.substr(5,2);

    double min = (int)1e+308;
    int index=100;
    for(int i=0; i<8; i++){
      if(d(r,g,b,i) < min ){
	index = i;
	min = d(r,g,b,i);
      }
      //   cout  << d(r,g,b,i) << " ";
    }
    cout << s[index] << "\n";
  }


}

C++: #include<iostream>
#include<cmath>
#include<string>
#define sq(a) ((a)*(a))
using namespace std;

int Conv(char c1, char c2){
	return (c1-'0')*0x10 + (c2-'0');
}
int dist(int R, int G, int B, int rR, int rG, int rB){
	return sq(R-rR) + sq(G-rG) + sq(B-rB);
}
string judge(int R, int G, int B ){
	int min_dist = 1<<30;
	string color;

	int r;
	
	r = dist( R, G, B, 0, 0, 0 );
	if( min_dist > r ){
		min_dist = r;
		color = "black";
	}
	r = dist( R, G, B, 0, 0, 0xFF );
	if( min_dist > r ){
		min_dist = r;
		color = "blue";
	}
	r = dist( R, G, B, 0, 0xFF, 0 );
	if( min_dist > r ){
		min_dist = r;
		color = "lime";
	}
	r = dist( R, G, B, 0, 0xFF, 0xFF );
	if( min_dist > r ){
		min_dist = r;
		color = "aqua";
	}
	r = dist( R, G, B, 0xFF, 0, 0 );
	if( min_dist > r ){
		min_dist = r;
		color = "red";
	}
	r = dist( R, G, B, 0xFF, 0, 0xFF );
	if( min_dist > r ){
		min_dist = r;
		color = "fuchsia";
	}
	r = dist( R, G, B, 0xFF, 0xFF, 0 );
	if( min_dist > r ){
		min_dist = r;
		color = "yellow";
	}
	r = dist( R, G, B, 0xFF, 0xFF, 0xFF );
	if( min_dist > r ){
		min_dist = r;
		color = "white";
	}
	return color;
}

int main(){
	while( true ){
		int R;
		int G;
		int B;
		string s;
		cin>>s;
		if(s.compare("0")==0)break;
		R = Conv(s[1],s[2]); G = Conv(s[3],s[4]); B = Conv(s[5],s[6]);
		cout << judge(R,G,B) << endl;
	}
	return 0;
}