Go: package main

import (
	"bufio"
	"os"
	"strings"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

type Color struct {
	name    string
	R, G, B int64
}

func main() {
	colors := []Color{
		{"black", 0, 0, 0},
		{"blue", 0, 0, 0xff},
		{"lime", 0, 0xff, 0},
		{"aqua", 0, 0xff, 0xff},
		{"red", 0xff, 0, 0},
		{"fuchsia", 0xff, 0, 0xff},
		{"yellow", 0xff, 0xff, 0},
		{"white", 0xff, 0xff, 0xff},
	}
	for scanner.Scan() {
		buf := strings.Split(scanner.Text(), "")
		if buf[0] == "0" {
			break
		}
		r, _ := strconv.ParseInt(strings.Join(buf[1:3], ""), 16, 64)
		g, _ := strconv.ParseInt(strings.Join(buf[3:5], ""), 16, 64)
		b, _ := strconv.ParseInt(strings.Join(buf[5:], ""), 16, 64)
		vmin := int64(3*0xff*0xff)
		var ans string
		for _, c := range colors {
			d := (r-c.R)*(r-c.R) + (g-c.G)*(g-c.G) + (b-c.B)*(b-c.B)
			if d < vmin {
				vmin = d
				ans = c.name
			}
		}
		fmt.Println(ans)
	}
}

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";
  
  }


}

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;
}