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

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
int stoi(char c){
  if('0' <= c && c <= '9')
    return c - '0';
  return c - 'a' + 10;
}

int pow(int n){
  return n * n;
}

int main(void){
  string s;
  string ans[8] = {
    "black",//	00	00	00
    "blue",//	00	00	ff
    "lime",//	00	ff	00
    "aqua",//	00	ff	ff
    "red",//	ff	00	00
    "fuchsia",//	ff	00	ff
    "yellow",//	ff	ff	00
    "white"//	ff	ff	ff
  };
  int num[8];
  int cnt = 0;
  rep(i,8)num[i] = i * 255;     
  //rep(i,8)cout<<ans[i] << " "<<num[i]<<endl;
  while(cin>>s){
    if(s == "0")break;
    int in[3];
    in[0] = stoi(s[1]) * 16 + stoi(s[2]);
    in[1] = stoi(s[3]) * 16 + stoi(s[4]);
    in[2] = stoi(s[5]) * 16 + stoi(s[6]);
    //rep(i,3)cout<<in[i]<<endl;
    int index = 0;
    unsigned long long diff = 100000000;
    rep(i,8){
      //cout<<i<<(i>>2)%2<<" "<<(i>>1)%2<<" "<<(i%2)<<endl;
   

      int box[3];
      rep(j,3){
	box[j] = (i>>(2-j))%2*255;
	//cout<<(i>>(2-j))%2*255<<" ";
      }
      //rep(j,3)cout<<in[j]<<" ";cout<<" "<<endl;
      
     
      unsigned long long int calc = 0;
      rep(j,3)calc += pow(in[j] - box[j]);
      calc = sqrt(calc);
	
									/*
      unsigned long long int calc = sqrt(				
					 pow(in[0]-(i>>2%2) * 255) + 
					 pow(in[1]-(i>>1%2) * 255) + 
					 pow(in[2]-(i>>0%2) * 255) 
									);
									//*/
      if(calc < diff){
	diff = calc;
	index = i;
	//cout<<"change"<<ans[i]<<endl;
      }
      //cout<<calc<<endl;

       //*/
    }
    cout<<ans[index]<<endl;
  }
}

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

using namespace std;

class color{
public:
	int r,g,b;
	string name;
	color(int x,int y,int z){r=x;g=y;b=z;}
	color(string s,int x, int y, int z){name = s; r=x; g=y; b=z;}

	double dist(const color arg){
		return sqrt(pow(abs(r - arg.r),2) +
				pow(abs(g - arg.g),2) +
				pow(abs(b - arg.b),2));
	}
};

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

int main(void){
	string str;
	vector<color> co;
	co.push_back(color("black",0,0,0));
	co.push_back(color("blue",0,0,255));
	co.push_back(color("lime",0,255,0));
	co.push_back(color("aqua",0,255,255));
	co.push_back(color("red",255,0,0));
	co.push_back(color("fuchsia",255,0,255));
	co.push_back(color("yellow",255,255,0));
	co.push_back(color("white",255,255,255));
	while(cin >> str){
		if(str[0] == '0') break;
		int c[3] = {0,0,0};
		char tmp;
		double dist = 1 << 30;
		int index;
		for(int i=0;i<3;i++){
			c[i] += c2d(str[i*2+1]) * 16;
			c[i] += c2d(str[i*2+2]);
		}
		color arg = color(c[0],c[1],c[2]);

		for(int i=0;i<8;i++){
			double tdist = co[i].dist(arg);
			if(dist > tdist){
				dist = tdist;
				index = i;
			}
		}
		cout << co[index].name << endl;
	}
}

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

int main() {
    vector<string> v{"black","blue","lime","aqua","red","fuchsia","yellow","white"};
    string s;
    while(cin >> s, s != "0") cout << v[4*(s[1]>'7')+2*(s[3]>'7')+1*(s[5]>'7')] << "\n";
    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]];
    }
    double mi=100000;
    int ms;
    rep(i,8){
      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 main() {
  const string c[] = { "black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white" };
  const int t[][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 s;
  while (cin >> s, s != "0") {
    int r = stoi(s.substr(1, 2), nullptr, 16);
    int g = stoi(s.substr(3, 2), nullptr, 16);
    int b = stoi(s.substr(5, 2), nullptr, 16);
    double mind = 500.0;
    int idx = -1;
    for (int i = 0; i < 8; i++) {
      double d = sqrt(pow(t[i][0] - r, 2) + pow(t[i][1] - g, 2) + pow(t[i][2] - b, 2));
      if (d < mind) {
        mind = d;
        idx = i;
      }
    }
    cout << c[idx] << "\n";
  }
}