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 <vector>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

string color[8] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
string strength[8] = {"000000", "0000ff", "00ff00", "00ffff", "ff0000", "ff00ff", "ffff00", "ffffff"};

int toi(string s){
    int ret = 0;
    rep(i, s.size()){
        string t = s.substr(i, 1);
        if('0' <= t[0] && t[0] <= '9') ret += stoi(t);
        else ret += t[0]-'a'+10;
        if(i != s.size()-1) ret *= 16;
    }
    return ret;
}

vector<int> rgb(string s){
    vi ret;
    rep(i, 3){
        string t = s.substr(i*2, 2);
        ret.pb(toi(t));
    }
    return ret;
}

int main(){
    string  s;
    while(cin >> s, s!="0"){
        s = s.substr(1);
        vi c = rgb(s);
        double m = inf;
        int ans = 0;
        rep(i, 8){
            vi d = rgb(strength[i]);
            double ret = sqrt(pow(c[0]-d[0], 2)+pow(c[1]-d[1], 2)+pow(c[2]-d[2], 2));
            if(m > ret){ans = i; m = ret;}
        }
        cout << color[ans] << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;

int hext(string a){
	int c,d;
	if(a[0]>='0'&&a[0]<='9')c=a[0]-'0';
	else c=a[0]-'a'+10;
	
	if(a[1]>='0'&&a[1]<='9')d=a[1]-'0';
	else d=a[1]-'a'+10;
	
	return c*16+d;
	}

int main(){
	string s;
	while(cin>>s&&s!="0"){
		int r,g,b;
		r=hext(s.substr(1,2));
		g=hext(s.substr(3,2));
		b=hext(s.substr(5,2));
		
		string ans;
		int d=1e9;
		if(d>((r*r)+(g*g)+(b*b)))ans="black",d=((r*r)+(g*g)+(b*b));
		if(d>((r*r)+(g*g)+((b-255)*(b-255))))ans="blue",d=((r*r)+(g*g)+((b-255)*(b-255)));
		if(d>((r*r)+((g-255)*(g-255))+(b*b)))ans="lime",d=((r*r)+((g-255)*(g-255))+(b*b));
		if(d>((r*r)+((g-255)*(g-255))+((b-255)*(b-255))))ans="aqua",d=((r*r)+((g-255)*(g-255))+((b-255)*(b-255)));
		if(d>((r-255)*(r-255))+(g*g)+(b*b))ans="red",d=((r-255)*(r-255))+(g*g)+(b*b);
		if(d>((r-255)*(r-255))+(g*g)+((b-255)*(b-255)))ans="fuchsia",d=((r-255)*(r-255))+(g*g)+((b-255)*(b-255));
		if(d>((r-255)*(r-255))+((g-255)*(g-255))+(b*b))ans="yellow",d=((r-255)*(r-255))+((g-255)*(g-255))+(b*b);
		if(d>((r-255)*(r-255))+((g-255)*(g-255))+(b-255)*(b-255))ans="white";
		
		cout<<ans<<endl;
		
		}
		return 0;
	}

C++: #include <cstdio>
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
string color[] = {"black", "blue", "lime", "aqua",
    "red", "fuchsia", "yellow", "white"};
int nums[][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 convert(string str) {
    int res = 0;
    if ('0'<=str[0]&&str[0]<='9') {
        res += (str[0]-'0') * 16;
    } else if ('a'<=str[0]&&str[0]<='f') {
        res += (str[0]-'a'+10) * 16;
    }
    if ('0'<=str[1]&&str[1]<='9') {
        res += (str[1]-'0');
    } else if ('a'<=str[1]&&str[1]<='f') {
        res += (str[1]-'a'+10);
    }
    return res;
}

int main() {
    string str;
    while (cin >> str) {
        if (str == "0") break;
        double d = 10000000.0;
        string res;
        int r = convert(str.substr(1,2)), g = convert(str.substr(3,2)), b = convert(str.substr(5,2));
        for (int i=0; i<8; i++) {
            double tmp = sqrt(pow(r-nums[i][0], 2)+pow(g-nums[i][1], 2)+pow(b-nums[i][2], 2));
            if (tmp < d) {
                d = tmp;
                res = color[i];
            }
        }
        cout << res << endl;
    }
}

#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
string color[] = {"black", "blue", "lime", "aqua",
    "red", "fuchsia", "yellow", "white"};
int nums[][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 convert(string str) {
    int res = 0;
    if ('0'<=str[0]&&str[0]<='9') {
        res += (str[0]-'0') * 16;
    } else if ('a'<=str[0]&&str[0]<='f') {
        res += (str[0]-'a'+10) * 16;
    }
    if ('0'<=str[1]&&str[1]<='9') {
        res += (str[1]-'0');
    } else if ('a'<=str[1]&&str[1]<='f') {
        res += (str[1]-'a'+10);
    }
    return res;
}

int main() {
    string str;
    while (cin >> str) {
        if (str == "0") break;
        double d = 10000000.0;
        string res;
        int r = convert(str.substr(1,2)), g = convert(str.substr(3,2)), b = convert(str.substr(5,2));
        for (int i=0; i<8; i++) {
            double tmp = sqrt(pow(r-nums[i][0], 2)+pow(g-nums[i][1], 2)+pow(b-nums[i][2], 2));
            if (tmp < d) {
                d = tmp;
                res = color[i];
            }
        }
        cout << res << endl;
    }
}

C++: #include<iostream>
#include<string>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define INF 1e6
using namespace std;

int d(string s,int color[3]){
  int red=(s[1]-'0')*16+(s[2]-'0');
  int green=(s[3]-'0')*16+(s[4]-'0');
  int blue=(s[5]-'0')*16+(s[6]-'0');
  return sqrt(pow((red-color[0]),2)+pow((green-color[1]),2)+pow((blue-color[2]),2));
}

int cl[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 main(){
  string str;
  while(1){
    cin>>str;
    if(str=="0")break;
    int num=INF;
    string ans="";
    rep(i,8){
      if(num>d(str,cl[i])){
	if(i==0)ans="black";
	else if(i==1)ans="blue";
	else if(i==2)ans="lime";
	else if(i==3)ans="aqua";
	else if(i==4)ans="red";
	else if(i==5)ans="fuchsia";
	else if(i==6)ans="yellow";
	else if(i==7)ans="white";
	num=d(str,cl[i]);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}