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 <stdio.h>
#include <string.h>

#define SQ(X) ((X)*(X))

typedef struct{
    char name[8];
    int r,g,b;
} Color;

double getDist2(Color col1, Color col2);
void GetCol(Color *cp, char *st);
int getHex(char c);

int main(){
    Color col[8];
    Color inCol;
    double dist2;
    int nearest, nearestId;
    char buf[16];
    
    // init color table
    col[0].r=0x00; col[0].g=0x00; col[0].b=0x00; strcpy(col[0].name, "black");
    col[1].r=0x00; col[1].g=0x00; col[1].b=0xff; strcpy(col[1].name, "blue");
    col[2].r=0x00; col[2].g=0xff; col[2].b=0x00; strcpy(col[2].name, "lime");
    col[3].r=0x00; col[3].g=0xff; col[3].b=0xff; strcpy(col[3].name, "aqua");
    col[4].r=0xff; col[4].g=0x00; col[4].b=0x00; strcpy(col[4].name, "red");
    col[5].r=0xff; col[5].g=0x00; col[5].b=0xff; strcpy(col[5].name, "fuchsia");
    col[6].r=0xff; col[6].g=0xff; col[6].b=0x00; strcpy(col[6].name, "yellow");
    col[7].r=0xff; col[7].g=0xff; col[7].b=0xff; strcpy(col[7].name, "white");
    
    while (scanf("%s",buf), buf[0]!='0'){
        GetCol(&inCol, buf);
        nearest = 65536*4;
        for (int i=0; i<8; i++){
            dist2 = getDist2(col[i], inCol);
            if (dist2 < nearest) nearest=dist2, nearestId=i;
        }
        printf("%s\n", col[nearestId].name);
    }    
    return 0;
}

double getDist2(Color col1, Color col2){
    return SQ(col1.r-col2.r)+SQ(col1.g-col2.g)+SQ(col1.b-col2.b);
}

void GetCol(Color *cp, char *st){
    cp->r = getHex(st[1])*0x10 + getHex(st[2]);
    cp->g = getHex(st[3])*0x10 + getHex(st[4]);
    cp->b = getHex(st[5])*0x10 + getHex(st[6]);
}

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

C++: #include<bits/stdc++.h>
#define INF 2100000000
using namespace std;
int main(void)
{
	int i,j,k,a,b,c,mini;
	char color[8][15]={"black","blue","lime","aqua",
				  "red","fuchsia","yellow","white"};
	int suu[16]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},
		red[8]={0,0,0,0,255,255,255,255},
		lime[8]={0,0,255,255,0,0,255,255},
		blue[8]={0,255,0,255,0,255,0,255};
	char sin[17]={"0123456789abcdef"};
	char pu[8];
	while(1) {
		cin>>pu;
		if(pu[0]=='0') break;
		a=b=c=0;
		for(i=1;i<8;i++) {
			for(j=0;j<16;j++) {
				if(pu[i]==sin[j]) {
					if(i<=2) {
						if(i%2==1)a+=suu[j]*16;
						else a+=suu[j];
					}
					else if(i<=4) {
						if(i%2==1) b+=suu[j]*16;
						else b+=suu[j];
					}
					else {
						if(i%2==1) c+=suu[j]*16;
						else c+=suu[j];
					}
					break;
				}
			}
		}
		mini=INF;
		int d,x=0;
		for(i=0;i<8;i++) {
			d=((a-red[i])*(a-red[i]))+
				((b-lime[i])*(b-lime[i]))+
				((c-blue[i])*(c-blue[i]));
			if(mini>d) {
				mini=d;
				x=i;
			}
		}
		cout<<color[x]<<endl;
	}
}

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

int main(){
  string data;
  int f1,f2;

  while(1){
    getline(cin,data);
    if(data[0] == '0') return 0;
    f1 = f2 = 0
    for(int i = 0; i  < 10; i++){
      if(data[1] == i)
	f1 = 1;
      if(data[2] == i)
	f2 = 1;
    }
    if(fa == 1&&f2 == 1){
      data[1] = 0;
      data[2] = 0;
    }else{
      data[1] == f;
      data[2] == f;
    } 
    for(int i = 0; i  < 10; i++){
      if(data[3] == i)
	f1 = 1;
      if(data[4] == i)
	f2 = 1;
    }
    if(fa == 1&&f2 == 1){
      data[3] = 0;
      data[4] = 0;
    }else{
      data[3] == f;
      data[4] == f;
    } 
    for(int i = 0; i  < 10; i++){
      if(data[5] == i)
	f1 = 1;
      if(data[6] == i)
	f2 = 1;
    }
    if(fa == 1&&f2 == 1){
	    data[5] = 0;
	    data[6] = 0;
    }else{
      data[5] == f;
      data[6] == f;
    } 
    
    if(data[1] == 0 && data[2] == 0){
      if(data[3] == 0&& data[4] == 0){
	if(data[5] == 0&& data[6] == 0){
	  cout << "black" <<endl;
	}else{
	  cout << "blue" << endl;
	}
      }
      else{
	if(data[5] == 0&&data[6] == 0){
	  cout << "linme" << endl;
	  }else{
	  cout << "aqua" << endl;
	}
      }
    }
    if(data[1] == f && data[2] == f){
      if(data[3] == f&& data[4] == f){
	if(data[5] == f&& data[6] == f){
	  cout << "white" <<endl;
	}else{
	  cout << "yellow"<< endl;
	}
      }
      else{
	if(data[5] == 0&&data[6] == 0){
	  cout << "red" << endl;
	  }else{
	  cout << "fuchsia" << endl;
	}
      }
    }
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int a[6],c[3],d[8][3];
string s,na[]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};

int main(){
	for(int i=0;i<8;i++){
		d[i][0]=i/4*255;
		d[i][1]=(i/2)%2*255;
		d[i][2]=i%2*255;
	}
	while(cin>>s){
		if(s=="0")return 0;
		for(int i=1;i<7;i++){
			if(isdigit(s[i]))a[i-1]=s[i]-'0';
			else a[i-1]=s[i]-'a'+10;
			if(!(i%2))c[i/2-1]=a[i-1]+a[i-2]*16;
		}
		int df=999999,no;
		for(int i=0;i<8;i++){
			int sum=0;
			for(int j=0;j<3;j++)sum+=(c[j]-d[i][j])*(c[j]-d[i][j]);
			if(sum<df){no=i;df=sum;}
		}
		cout<<na[no]<<endl;
	}
}

C++: #include <stdio.h>

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

int solve(int r, int g, int b){
    int min = 0; int mind = 200000;
    for(int i = 0; i < 8; i++){
        int r0 = ((i>>2)&1)*0xff, g0 = ((i>>1)&1)*0xff, b0 = ((i>>0)&1)*0xff;
        //pf("%d,%d,%d : %d,%d,%d\n", r,g,b,r0,g0,b0);
        int d = (r-r0)*(r-r0)+(g-g0)*(g-g0)+(b-b0)*(b-b0);
        if(mind > d){
            mind = d, min = i;
        }
    }
    if(min >= 8) throw;
    return min;
}

int main(){
    int n;
    char buf[16];
    while(fgets(buf,sizeof(buf),stdin)){
        if(buf[0] == '0') break;
        sscanf(buf+1,"%x",&n);
        int i = solve((n>>16)&0xff,(n>>8)&0xff,n&0xff);
        printf("%s\n", t[i]);
    }
    return 0;
}