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

using namespace std;

int main(){

	string inp;
	string base = ("0123456789abcdef" );
	string scol[8] = { "black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white" };
	int icol[8][3] = { { 0, 0, 0 }, { 0, 0, 256 }, { 0, 256, 0 }, { 0, 256, 256 }, { 256, 0, 0 }, { 256, 0, 256 }, { 256, 256, 0 }, { 256, 256, 256 } };
	int r, g, b;
	int ans;
	double ansnum;

	while (1){

		cin >> inp;
		if (inp == "0") break;

		r = base.find(inp[2]) * 1 + base.find(inp[1]) * 16;
		g = base.find(inp[4]) * 1 + base.find(inp[3]) * 16;
		b = base.find(inp[6]) * 1 + base.find(inp[5]) * 16;

		ans = 0;
		ansnum = pow(r - icol[0][0], 2.0) + pow(g - icol[0][1], 2.0) + pow(b - icol[0][2], 2.0);
		for (int i = 1; i < 8; i++){
			if (ansnum>pow(r - icol[i][0], 2.0) + pow(g - icol[i][1], 2.0) + pow(b - icol[i][2], 2.0)){
				ans = i;
				ansnum = pow(r - icol[i][0], 2.0) + pow(g - icol[i][1], 2.0) + pow(b - icol[i][2], 2.0);
			}
		}

		cout << scol[ans] << endl;

	}
}

C++: #include<iostream>
#include<string>
using namespace std;
string s;
string color() {
	char l[6];
	for (int i = 0; i < 6; i++) {
		l[i] = s[i + 1];
	}
	int r, g, b;
	int z[6];
	for (int i = 0; i < 6; i++) {
		if (l[i] == '0') {
			z[i] = 0;
		}
		else if (l[i] == '1') {
			z[i] = 1;
		}
		else if (l[i] == '2') {
			z[i] = 2;
		}
		else if (l[i] == '3') {
			z[i] = 3;
		}
		else if (l[i] == '4') {
			z[i] = 4;
		}
		else if (l[i] == '5') {
			z[i] = 5;
		}
		else if (l[i] == '6') {
			z[i] = 6;
		}
		else if (l[i] == '7') {
			z[i] = 7;
		}
		else if (l[i] == '8') {
			z[i] = 8;
		}
		else if (l[i] == '9') {
			z[i] = 9;
		}
		else if (l[i] == 'a') {
			z[i] = 10;
		}
		else if (l[i] == 'b') {
			z[i] = 11;
		}
		else if (l[i] == 'c') {
			z[i] = 12;
		}
		else if (l[i] == 'd') {
			z[i] = 13;
		}
		else if (l[i] == 'e') {
			z[i] = 14;
		}
		else if (l[i] == 'f') {
			z[i] = 15;
		}
	}
	r = z[0] * 16 + z[1];
	g = z[2] * 16 + z[3];
	b = z[4] * 16 + z[5];
	if (r <= 127) {
		if (g <= 127) {
			if (b <= 127) {
				return "black";
			}else {
				return "blue";
			}
		}else if (b <= 127) {
				return "lime";
			  }else {
				return "aqua";
			  }
	}
	else if (g <= 127) {
			if (b <= 127) {
				return "red";
			}else{
				return "fuchsia";
			}
		}
		else if (b <= 127) {
				return "yellow";
			}else{
				return "white";
			}
}

int main() {
	string g[1001];
	int x;
	for (int i = 0;; i++){
		cin >> s;
		if (s == "0") {
			x = i;
			break;
		}
		g[i] = color();
	}
	for (int i = 0; i < x; i++){
		cout << g[i] << endl;
	}
	char c;
	cin >> c;
	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<string>
using namespace std;
int main(){
  char c[10];
  int r,g,b,id;
  string str[8] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};
  while(scanf("%s",c),c[0]!='0'){
    r = g = b = 0;
    if('0'<=c[1] && c[1]<='9') r += (c[1]-'0')*16;
    else r += (c[1]-'A'+10)*16;
    if('0'<=c[2] && c[2]<='9') r += (c[2]-'0');
    else r += (c[2]-'A'+10);
    if('0'<=c[3] && c[3]<='9') g += (c[3]-'0')*16;
    else g += (c[3]-'A'+10)*16;
    if('0'<=c[4] && c[4]<='9') g += (c[4]-'0');
    else g += (c[4]-'A'+10);
    if('0'<=c[5] && c[5]<='9') b += (c[5]-'0')*16;
    else b += (c[5]-'A'+10)*16;
    if('0'<=c[6] && c[6]<='9') b += (c[6]-'0');
    else r += (c[6]-'A'+10);
    id = 0;
    if(r >=123) id += 4;
    if(g >=123) id += 2;
    if(b >=123) id += 1;
    cout << str[id] << endl;
  }
  return(0);
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

string in;
const string name[8] = {
  "black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"
};

bool is_digit(char c) { return '0' <= c && c <= '9'; }
int c2i(char c) { return c - '0'; }

string solve() {
  in.erase(0, 1);
  int my[3];
  rep (i,3) my[i] = 0;
  rep (i,3) {
    if (is_digit(in[i*2])) {
      my[i] = c2i(in[i*2]) * 16;
    } else {
      my[i] = (10 + (in[i*2] - 'a')) * 16;
    }
    
    if (is_digit(in[i*2+1])) {
      my[i] += c2i(in[i*2+1]);
    } else {
      my[i] += (10 + (in[i*2+1] - 'a'));
    }
  }
  
  int dk = 1 << 28, l = -1;
  rep (S,8) {
    int ar[3], temp = 0;
    rep (i,3) ar[i] = (S >> i & 1) ? 255 : 0 ;
    rep (i,3) temp += abs(ar[i] - my[i]);
    if (dk > temp) {
      dk = temp;
      l = S;
    }
  }
  return name[l];
}

int main() {
  while (cin >> in) {
    if (in == "0") break;
    cout << solve() << endl;
  }
  return 0;
}

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


int tmp[] = {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*16*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];
  }
  //  cout << ans << " ";
  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+300;
    int index;
    for(int i=0; i<8; i++){
      if(d(r,g,b,i) < min ){
	index = i;
	min = d(r,g,b,i);
      }
    }
    cout << s[index] << "\n";
  
  }


}