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<cfloat>
#include<cmath>
using namespace std;

int hexToDec(char x){
    if('0' <= x && x <= '9'){
        return x-'0';
    }else{
        return 10 + (x - 'a');
    }
}

int data[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 color[8] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};

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

        if(s == "0")    break;
    
        int r, g, b;
        r = 16 * hexToDec(s[1]) + hexToDec(s[2]);
        g = 16 * hexToDec(s[3]) + hexToDec(s[4]);
        b = 16 * hexToDec(s[5]) + hexToDec(s[6]);

        double dist = DBL_MAX;
        int ans;

        for(int i = 0; i < 8; i++){
            double tmp = sqrt(pow(r - data[i][0], 2.0) + pow(g - data[i][1], 2.0) + pow(b - data[i][2], 2.0));
            if(tmp < dist){
                dist = tmp;
                ans = i;
            }
        }

        cout << color[ans] << endl;
    }

    return 0;
}

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

const int INF = 1 << 30;

const int color[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} };
const string name[] = {"black", "blue", "lime", "aquq",
		       "red", "fuchsia", "yellow", "white" };

int main()
{
  string RGB;
  while (cin >> RGB) {
    if (RGB == "0")
      break;

    int R = strtol(RGB.substr(1, 2).c_str(), NULL, 16);
    int G = strtol(RGB.substr(3, 2).c_str(), NULL, 16);
    int B = strtol(RGB.substr(5, 2).c_str(), NULL, 16);

    int d = INF, index = 0;
    for (int i = 0; i < 8; ++i) {
      int dd = (R-color[i][0]) * (R-color[i][0])
	+ (G-color[i][1]) * (G-color[i][1])
	+ (B-color[i][2]) * (B-color[i][2]);

      if (d > dd) {
	d = dd;
	index = i;
      }
    }
    cout << name[index] << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int C = 8;

string cs[C] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
int R[C] = {0, 0, 0, 0, 255, 255, 255, 255};
int G[C] = {0, 0, 255, 255, 0, 0, 255, 255};
int B[C] = {0, 255, 0, 255, 0, 255, 0, 255};

int solve(int r, int g, int b){
  int d = 1e9, res = 0;
  REP(i, C){
    int _d = (r - R[i]) * (r - R[i]) + (g - G[i]) * (g - G[i]) + (b - B[i]) * (b - B[i]);
    if(_d < d){ d = _d; res = i; }
  }
  return res;
}

int main() {
  string s;
  char **buf;
  while(cin >>s && s != "0"){
    string _s = s, __s = s;
    int r = (int)strtol(s.substr(1, 2).c_str(), buf, 16);
    int g = (int)strtol(_s.substr(3, 2).c_str(), buf, 16);
    int b = (int)strtol(__s.substr(5, 2).c_str(), buf, 16);
    cout <<cs[solve(r, g, b)] <<endl;
  }
  return 0;
}

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

int hex2digit(const char x) {
    int res = 0;
    if ('0' <= x && x <= '9') {
        res += x - '0';
    } else if ('a' <= x && x <= 'f') {
        res += x - 'a' + 10;
    }
    return res;
}

int main() {
    const int red[] = {0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, };
    const int green[] = {0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, };
    const int blue[] = {0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, };
    const char* color[] = {
        "black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white",
    };
    while (true) {
        char input[8];
        cin >> input;
        if (input[0] == '0') {
            break;
        }
        int k = 0,
            r = hex2digit(input[1]) * 16 + hex2digit(input[2]),
            g = hex2digit(input[3]) * 16 + hex2digit(input[4]),
            b = hex2digit(input[5]) * 16 + hex2digit(input[6]);
        double minD = 1000000;
        for (int i = 0; i < (int) sizeof red / (int) sizeof *red; i++) {
            double d = sqrt(pow(r - red[i], 2) + pow(g - green[i], 2) + pow(b - blue[i], 2));
            if (d < minD) {
                minD = d;
                k = i;
            }
        }
        cout << color[k] << endl;
    }
}