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++: #define _USE_MATH_DEFINES
#define MAX_N 1000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

static const double eps = 1e-8;

struct COLOR{
	string name;
	string R;
	string G;
	string B;
};

int hex2dec(string str){
	const char hex[] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
	return 16 * (int)lower_bound(hex,hex+16,str[0]) + (int)lower_bound(hex,hex+16,str[1]);
}

int main(){

	struct COLOR color[] = {
		"black","00","00","00",
		"blue","00","00","ff",
		"lime","00","ff","00",
		"aqua","00","ff","ff",
		"red","ff","00","00",
		"fuchsia","ff","00","ff",
		"yellow","ff","ff","00",
		"white","ff","ff","ff",
	};

	string str;
	while(cin >> str){
		if(str.size() == 1 && str[0] == '0') break;
		int r = hex2dec(str.substr(1,2));
		int g = hex2dec(str.substr(3,2));
		int b = hex2dec(str.substr(5,2));

		int dk = 10000000;
		int idx=0;
		for(int i=0;i<sizeof(color)/sizeof(struct COLOR); i++){
			int tmp;
			if(dk > (tmp=((r - hex2dec(color[i].R)) * (r - hex2dec(color[i].R))
				+ (g - hex2dec(color[i].G)) * (g - hex2dec(color[i].G))
				+ (b - hex2dec(color[i].B)) * (b - hex2dec(color[i].B))))){
					dk = tmp;
					idx=i;
			}
		}

		printf("%s\n",color[idx].name.c_str());
	}

}

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

int main()
{
  vector< vector<int> > table( 8, vector<int>(3) );
  vector<string> name(8);
  vector<int> color(3);
  char c;
  int i, near, dist, t;
  table[0][0] = 0; table[0][1] = 0; table[0][2] = 0;
  table[1][0] = 0; table[1][1] = 0; table[1][2] = 255;
  table[2][0] = 0; table[2][1] = 255; table[2][2] = 0;
  table[3][0] = 0; table[3][1] = 255; table[3][2] = 255;
  table[4][0] = 255; table[4][1] = 0; table[4][2] = 0;
  table[5][0] = 255; table[5][1] = 0; table[5][2] = 255;
  table[6][0] = 255; table[6][1] = 255; table[6][2] = 0;
  table[7][0] = 255; table[7][1] = 255; table[7][2] = 255;
  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 (cin>>c, c!='0') {
    color.clear();
    for (i = 0; i < 3; i++) {
      cin>>c;
      if ('a' <= c) color[i] = c-'a'+10;
      else color[i] = c-'0';
      color[i] *= 16;
      cin>>c;
      if ('a' <= c) color[i] += c-'a'+10;
      else color[i] += c-'0';
    }
    dist = INT_MAX;
    near = 0;
    for (i = 0; i < 8; i++) {
      t = (table[i][0]-color[0])*(table[i][0]-color[0]) + (table[i][1]-color[1])*(table[i][1]-color[1]) + (table[i][2]-color[2])*(table[i][2]-color[2]);
      if (t < dist) {
	near = i;
	dist = t;
      }
    }
    cout<<name[near]<<endl;
  }
  return 0;
}

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

const char *name[] = {
	"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white",
};

int main(){
	int r, g, b;
	while(scanf(" #%2x%2x%2x", &r, &g, &b) == 3){
		puts(name[(r > 127) * 4 + (g > 127) * 2 + (b > 127)]);
	}
}

C++: // 0176
#include <iostream>
#include <string>
#define  N   255
using namespace std;

int c_table[8][3] = {{0,0,0}, {0,0,N}, {0,N,0}, {0,N,N}, {N,0,0}, {N,0,N}, {N,N,0}, {N,N,N}};

int conv_16(char c){
	if((c >= '0') && (c <= '9'))
		return c-'0';
	else if((c >= 'a') && (c <= 'f'))
		return c-'a'+10;
}

int dk(int co1[3], int co2[3]){
	int d = 0;

	for(int i=0;i<3;i++)
		d += (co1[i]-co2[i])*(co1[i]-co2[i]);

	return d;
}

int main(){
	while(1){
		string str;
		cin>>str;

		if(str == "0")
			break;

		int rgb[3], d=3*N*N, color=0;
		for(int i=0;i<3;i++)
			rgb[i] = 16*conv_16(str[2*i+1]) + conv_16(str[2*i+2]);
	
		
		for(int i=0;i<8;i++)
			if(d > dk(c_table[i], rgb)){
				d = dk(c_table[i], rgb);
				color = i;
			}

		if(color == 0)
			cout<<"black"<<endl;
		else if(color == 1)
			cout<<"blue"<<endl;
		else if(color == 2)
			cout<<"lime"<<endl;
		else if(color == 3)
			cout<<"aqua"<<endl;
		else if(color == 4)
			cout<<"red"<<endl;
		else if(color == 5)
			cout<<"fuchsia"<<endl;
		else if(color == 6)
			cout<<"yellow"<<endl;
		else if(color == 7)
			cout<<"white"<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
  
// #define int long long
#define pb push_back
#define print(Target) cout << Target << '\n'

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, a, n) for (int i = (a); i < (n); i++)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}

struct COL{
  int n;
  string name;
};

const int c[8][3] = {{0, 0, 0}, {0, 0, 0xff}, {0, 0xff, 0}, {0, 0xff, 0xff}, {0xff, 0, 0}, {0xff, 0, 0xff}, {0xff, 0xff, 0}, {0xff, 0xff, 0xff}};

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

bool cmp(COL lhs, COL rhs)
{
  return (lhs.n < rhs.n);
}

signed main()
{
  //ios::sync_with_stdio(false);
  char sr[2], sg[2], sb[2];
  char sh;
    
  while (scanf("%1s", &sh), sh != '0'){
    COL col[8];
    scanf("%2s%2s%2s", sr, sg, sb);
    int r = strtol(sr, NULL, 16),
        g = strtol(sg, NULL, 16),
        b = strtol(sb, NULL, 16);

    REP(i, 8){
      col[i].n = (c[i][0] - r) * (c[i][0] - r) + (c[i][1] - g) * (c[i][1] - g) + (c[i][2] - b) * (c[i][2] - b);
      col[i].name = s[i];
    }

    sort(col, col + 8, cmp);
    print(col[0].name);
  }

  return (0);
}