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<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<regex>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

//n??????
//Radix r("0123456789abcdef");
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0208
class Radix {
private:
	const char* s;
	int a[128];
public:
	Radix(const char* s = "0123456789ABCDEF") : s(s) {
		for (int i = 0; s[i]; i++) a[(int)s[i]] = i;
	}
	//10?????´??° ??? n???????????????
	string format(long long x, int n) {
		if (!x) return "0";
		char t[64] = {};
		int i;
		for (i = 62; x; i--) {
			t[i] = s[x % n];
			x /= n;
		}
		return string(t + i + 1);
	}
	//m??????????????? ??? n???????????????
	string format(const string &t, int m, int n) {
		return format(format(t, m), n);
	}
	//m??????????????? ??? 10?????´??°
	long long format(const string &t, int m) {
		long long sm = a[(int)t[0]];
		for (int i = 1; i < (int)t.length(); i++)
			sm = sm * m + a[(int)t[i]];
		return sm;
	}
};


signed main() {
	string color[] = { "black","blue","lime","aqua","red","fuchsia","yellow","white" };
	int R[] = { 0,0,0,0,0xff,0xff,0xff,0xff };
	int G[] = { 0,0,0xff,0xff,0,0,0xff,0xff };
	int B[] = { 0,0xff,0,0xff,0,0xff,0,0xff };
	Radix r("0123456789abcdef");
	for (string s; cin >> s&&s != "0";) {
		int RR, GG, BB;
		RR = r.format(s.substr(1, 2), 16);
		GG = r.format(s.substr(3, 2), 16);
		BB = r.format(s.substr(5, 2), 16);
		int min = INF, ans;
		rep(i, 0, 8) {
			int d = (RR - R[i])*(RR - R[i]) + (GG - G[i])*(GG - G[i]) + (BB - B[i])*(BB - B[i]);
			if (min > d) {
				min = d;
				ans = i;
			}
		}
		cout << color[ans] << endl;
	}
	return 0;
}

C++: // 2011/02/19 Tazoe

#include <iostream>
#include <string>
using namespace std;

int main()
{
	while(true){
		string col;
		cin >> col;
		if(col=="0")
			break;

		if(col[1]>='0'&&col[1]<='7')
			if(col[3]>='0'&&col[3]<='7')
				if(col[5]>='0'&&col[5]<='7')
					cout << "black" << endl;
				else
					cout << "blue" << endl;
			else
				if(col[5]>='0'&&col[5]<='7')
					cout << "lime" << endl;
				else
					cout << "aqua" << endl;
		else
			if(col[3]>='0'&&col[3]<='7')
				if(col[5]>='0'&&col[5]<='7')
					cout << "red" << endl;
				else
					cout << "fuchsia" << endl;
			else
				if(col[5]>='0'&&col[5]<='7')
					cout << "yellow" << endl;
				else
					cout << "white" << endl;
	}

	return 0;
}

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;     
  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){

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

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

typedef long long ll;
typedef pair<int, int> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int hen(char a) {
  if((int)a - 48 >= 0 && (int)a - 48 < 10) return (int)a - 48;
  if(a == 'a') return 10;
  else if(a == 'b') return 11;
  else if(a == 'c') return 12;
  else if(a == 'd') return 13;
  else if(a == 'e') return 14;
  else return 15;
}

int main() {
  string s;
  while(cin >> s) {
    if(s == "0") return 0;
    int r = hen(s[1]) * 16 + hen(s[2]);
    int g = hen(s[3]) * 16 + hen(s[4]);
    int b = hen(s[5]) * 16 + hen(s[6]);

    int ans = INT_MAX;
    string mans;
    if(r * r + g * g + b * b < ans) ans = r * r + g * g + b * b, mans = "black";
    if(r * r + g * g + (b - 255) * (b - 255) < ans) ans = r * r + g * g + (b - 255) * (b - 255), mans = "blue";
    if(r * r + (g - 255) * (g - 255) + b * b < ans) ans = r * r + (g - 255) * (g - 255) + b * b, mans = "lime";
    if(r * r + (g - 255) * (g - 255) + (b - 255) * (b - 255) < ans) ans = r * r + (g - 255) * (g - 255) + (b - 255) * (b - 255), mans = "aqua";
    if((r - 255) * (r - 255) + g * g + b * b < ans) ans = (r - 255) * (r - 255) + g * g + b * b, mans = "red";
    if((r - 255) * (r - 255) + g * g + (b - 255) * (b - 255) < ans) ans = (r - 255) * (r - 255) + g * g + (b - 255) * (b - 255), mans = "fuchsia";
    if((r - 255) * (r - 255) + (g - 255) * (g - 255) + b * b < ans) ans = (r - 255) * (r - 255) + (g - 255) * (g - 255) + b * b, mans = "yellow";
    if((r - 255) * (r - 255) + (g - 255) * (g - 255) + (b - 255) * (b - 255) < ans) ans = (r - 255) * (r - 255) + (g - 255) * (g - 255) + (b - 255) * (b - 255), mans = "white";

    cout << mans << endl;
  }
}