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<string>
using namespace std;

int main()
{
    string str;
    string s[8] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};
    int a[150] = {};
    int b[8][3];

    for( int i = '0'; i < '0' + 10; i++ )
        a[i] = i - '0';
    for( int i = 'a'; i < 'a' + 6; i++ )
        a[i] = i - 'a' + 10;

    for( int i = 0; i < 8; i++ )
    {
        if( i / 4 == 0 )
            b[i][0] = 0;
        else
            b[i][0] = 255;

        if( i == 0 || i == 1 || i == 4 || i == 5 )
            b[i][1]= 0;
        else
            b[i][1] = 255;   

        if( i % 2 == 0 )
            b[i][2] = 0;
        else
            b[i][2] = 255;
    }

    while( cin >> str )
    {
        if( str == "0" )
            break;
            
        int r = a[str[1]] * 16 + a[str[2]], g = a[str[3]] * 16 + a[str[4]], d = a[str[5]] * 16 + a[str[6]];
        int res = 0;
        int min = 100000000;
        for( int i = 0; i < 8; i++ )
        {
            if( ( b[i][0] - r ) * ( b[i][0] - r ) + ( b[i][1] - g ) * ( b[i][1] - g ) + ( b[i][2] - d ) * ( b[i][2] - d ) < min )
            {
                min = ( b[i][0] - r ) * ( b[i][0] - r ) + ( b[i][1] - g ) * ( b[i][1] - g ) + ( b[i][2] - d ) * ( b[i][2] - d );
                res = i;
            }
        }
        cout << s[res] << endl;
    }


    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

int main(){
	while(1){
		char n[9];
		int index, c[3] = {0};
		double min = 1000, d;
	
		scanf(" %s", n);
		if(strcmp(n, "0") == 0) break;
		
		for(int i=0; i<3; i++){
			if(n[2*i+1] <= '9') c[i] += 16*(n[2*i+1]-'0');
			else c[i] += 16*(n[2*i+1]-'a'+10);
			
			if(n[2*i+2] <= '9') c[i] += n[2*i+2]-'0';
			else c[i] += n[2*i+2]-'a'+10;
		}
		
		/*for(int i=0; i<3; i++)
			printf("%d ", c[i]);*/
		
		for(int i=0; i<8; i++){
			int p;
			if(i%4==0 || i%4==1) p=0;
			else p=1;
		
			d=sqrt( pow(c[0]-(i/4)*255, 2) + pow(c[1]-p*255, 2) + pow(c[2]-(i%2)*255, 2) );
			if(min > d){
				min = d;
				index = i;
			}
		}
		
		if(index==0) printf("black\n");
		else if(index==1) printf("blue\n");
		else if(index==2) printf("lime\n");
		else if(index==3) printf("aqua\n");
		else if(index==4) printf("red\n");
		else if(index==5) printf("fuchsia\n");
		else if(index==6) printf("yellow\n");
		else if(index==7) printf("white\n");

	}

	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'));
    }
  }
  
  double dk = double(1 << 28);
  int l = -1;
  rep (S,8) {
    int ar[3], temp = 0;
    rep (i,3) ar[2-i] = (S >> i & 1) ? 255 : 0 ;
    rep (i,3) {
      temp += (ar[i] - my[i]) * (ar[i] - my[i]);
    }
    double d = sqrt(double(temp));
    if (dk > d) {
      dk = d;
      l = S;
    }
  }
  return name[l];
}

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

C++: #include<stdio.h>
int main()
{
	char*s[]={"black","blue","lime","aqua","red","fuchsia","yellow","white"},x;
	int n;
	while(scanf(" %c%x",&x,&n),x-'0')
		puts(s[((n>>16)>127)*4+((n&0xff00)>32767)*2+((n&255)>127)]);
	return 0;
}