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

int main()
{
  string s;
  for(;cin>>s,s!="0";)
    {
      int r=0,g=0,b=0;
      for(int i=1;i<3;i++)
	{
	  r*=16;
	  if(s[i]>='0'&&s[i]<='9')
	      r+=s[i]-'0';
	  else
	    r+=s[i]-'a'+10;
	}
      for(int i=3;i<5;i++)
	{
	  g*=16;
	  if(s[i]>='0'&&s[i]<='9')
	      g+=s[i]-'0';
	  else
	   g+=s[i]-'a'+10;
	}
      for(int i=5;i<7;i++)
	{
	  b*=16;
	  if(s[i]>='0'&&s[i]<='9')
	      b+=s[i]-'0';
	  else
	    b+=s[i]-'a'+10;
	}
      string color[]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
      int rk[]={0,0,0,0,0xff,0xff,0xff,0xff};
      int gk[]={0,0,0xff,0xff,0,0,0xff,0xff};
      int bk[]={0,0xff,0,0xff,0,0xff,0,0xff};
      
      int ans=0;
      for(int i=1;i<8;i++)
	{
	  int a1=(r-rk[i])*(r-rk[i])+(g-gk[i])*(g-gk[i])+(b-bk[i])*(b-bk[i]);
	  int a2=(r-rk[ans])*(r-rk[ans])+(g-gk[ans])*(g-gk[ans])+(b-bk[ans])*(b-bk[ans]);
	  // /cout<<a1<<endl;
	  //cout<<a2<<endl;
	  if(a1<a2)
	    ans=i;
	}
      cout<<color[ans]<<endl;
    }
}

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

#define sq(c) ((c)*(c))

vector<double> col8[8];

vector<double> col16to10( string str ) {
  string s;
  
  str = str.substr(1, 6);
  vector<double> col(3);
  for(int i=0; i<3; i++) {
    s = str.substr(i*2, 2);
    if(isalpha(s[1]))	col[i] = s[1]-'a' + 10;
    else col[i] = s[1]-'0';
    
    if(isalpha(s[0]))	col[i] += ( s[0]-'a' + 10 ) * 16;
    else col[i] += ( s[0]-'0' ) * 16;
  }

  return col;
}

double calc( vector<double> col, int i ) {
  return sqrt( sq(col[0]-col8[i][0]) + sq(col[1]-col8[i][1]) + sq(col[2]-col8[i][2]) );
}

int main() {
  string str;
  
  col8[0] = col16to10("#000000");
  col8[1] = col16to10("#0000ff");
  col8[2] = col16to10("#00ff00");
  col8[3] = col16to10("#00ffff");
  col8[4] = col16to10("#ff0000");
  col8[5] = col16to10("#ff00ff");
  col8[6] = col16to10("#ffff00");
  col8[7] = col16to10("#ffffff");
  
  while(getline(cin, str)) {
    if( str == "0" ) break;
    
    vector<double> col(3);
    col = col16to10( str );
    
    double mn = 1<<20;
    int num = 0;
    for(int i=0; i<8; i++) {
      double temp = mn;
      mn = min( mn, calc(col, i) );
      if( mn < temp ) num = i;
    }
    
    switch( num ) {
    case 0: cout << "black"; break;
    case 1: cout << "blue";  break;
    case 2: cout << "lime";  break;
    case 3: cout << "aqua";  break;
    case 4: cout << "red";   break;
    case 5: cout << "fuchsia"; break;
    case 6: cout << "yellow"; break;
    case 7: cout << "white"; break;
    }
    cout << endl;
  }
  
  return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int in[256]={0};
int han[3][8]={
  {  0,  0,  0,  0,256,256,256,256},
  {  0,  0,256,256,  0,  0,256,256},
  {  0,256,  0,256,  0,256,  0,256}
};
string ss[8]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
int main(){
  string s;
  loop(i,'0','9'+1)in[i]=i-'0';
  loop(i,'a','g')in[i]=i-'a'+10;
  while(cin>>s,s.size()!=1||s[0]!='0'){
    int a[3]={0};
    rep(i,3){
      a[i]=in[s[2*i+1]]*16+in[s[2*i+2]];
    }
    long long int mi=1000000000;
    int ms;
    rep(i,8){
      long long int sum=0;
      rep(j,3)sum+=(han[j][i]-a[j])*(han[j][i]-a[j]);
      if(mi>sum){
	ms=i;
	mi=sum;
      }
    }
    cout<<ss[ms]<<endl;
  }
}

C++: #include <bits/stdc++.h>

using namespace std;

int hextod(char a,char b){
    int ret=0;
    if(isdigit(b))ret+=b-'0';
    else ret+=10+b-'a';
    if(isdigit(a))ret+=16*(a-'0');
    else ret+=16*(10+a-'a');
    return ret;
}

int main(){
    while(true){
        char un;
        cin>>un;
        if(un=='0')break;
        char r1,r2,g1,g2,b1,b2;
        cin>>r1>>r2>>g1>>g2>>b1>>b2;
        int r,g,b;
        r=hextod(r1,r2);
        g=hextod(g1,g2);
        b=hextod(b1,b2);

        vector<vector<int>> iro(8,vector<int>(3));
        for (int i = 0; i < 8; ++i) {
            if(i%2==0)iro[i][0]=0;
            else iro[i][0]=255;
            if(i%4==0||i%4==1)iro[i][1]=0;
            else iro[i][1]=255;
            if(i<4)iro[i][2]=0;
            else iro[i][2]=255;
        }
        vector<string> ironame={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
        int ans=-1;
        long long mdist=numeric_limits<int>::max();
        for (int i = 0; i < 8; ++i) {
            long long td=0;
            td+=(r-iro[i][2])*(r-iro[i][2]);
            td+=(g-iro[i][1])*(g-iro[i][1]);
            td+=(b-iro[i][0])*(b-iro[i][0]);
            if(td<mdist){
                ans=i;
                mdist=td;
            }
        }
        cout<<ironame[ans]<<endl;
    }

    return 0;
}

C++: #include<iostream>
#include<cmath>
#include<string>

using namespace std;

int main(){

	string inp;
	string base = { "0123456789abcdef" };
	string scol[8] = { "black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white" };
	int icol[8][3] = { { 0, 0, 0 }, { 0, 0, 256 }, { 0, 256, 0 }, { 0, 256, 256 }, { 256, 0, 0 }, { 256, 0, 256 }, { 256, 256, 0 }, { 256, 256, 256 } };
	int r, g, b;
	int ans;
	double ansnum;

	while (1){

		cin >> inp;
		if (inp == "0") break;

		r = base.find(inp[2]) * 1 + base.find(inp[1]) * 16;
		g = base.find(inp[4]) * 1 + base.find(inp[3]) * 16;
		b = base.find(inp[6]) * 1 + base.find(inp[5]) * 16;

		ans = 0;
		ansnum = sqrt(pow(r - icol[0][0], 2.0) + pow(g - icol[0][1], 2.0) + pow(b - icol[0][2], 2.0));
		for (int i = 1; i < 8; i++){
			if (ansnum>sqrt(pow(r - icol[i][0], 2.0) + pow(g - icol[i][1], 2.0) + pow(b - icol[i][2], 2.0))){
				ans = i;
				ansnum = sqrt(pow(r - icol[i][0], 2.0) + pow(g - icol[i][1], 2.0) + pow(b - icol[i][2], 2.0));
			}
		}

		cout << scol[ans] << endl;

	}
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <vector>

using namespace std;

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

int main(){
	
	string str;
	
	while(true){
		cin >> str;
		if(str[0] == '0'){
			break;
		}
		int ans = 0;
		if(str[1] < '0' || str[1] > '7'){
			ans += 4;
		}
		if(str[3] < '0' || str[3] > '7'){
			ans += 2;
		}
		if(str[5] < '0' || str[5] > '7'){
			ans += 1;
		}
		cout << s[ans] << endl;
	}
	
	return 0;
}