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<string>
#include<cstring>
#include<cctype>
#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=0,blue=0,green=0;
  if(!isdigit(s[1]))red+=(s[1]-'a'+10)*16;
  else red+=(s[1]-'0')*16;
  if(!isdigit(s[2]))red+=(s[2]-'a'+10);
  else red+=(s[2]-'0');
  if(!isdigit(s[3]))green+=(s[3]-'a'+10)*16;
  else green+=(s[3]-'0')*16;
  if(!isdigit(s[4]))green+=(s[4]-'a'+10);
  else green+=(s[4]-'0');
  if(!isdigit(s[5]))blue+=(s[5]-'a'+10)*16;
  else blue+=(s[5]-'0')*16;
  if(!isdigit(s[6]))blue+=(s[6]-'a'+10);
  else blue+=(s[6]-'0');
  return 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;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

int R[8], G[8], B[8];
string color[8] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};

int calc_d(int r, int g, int b, int i){
  return (r - R[i]) * (r - R[i]) + (g - G[i]) * (g - G[i]) + (b - B[i]) * (b - B[i]);
}

int main(){

  REP(i,8){
    if(i % 2 == 1){
      B[i] = 255;
    }
    if(i % 4 >= 2){
      G[i] = 255;
    }
    if(i >= 4){
      R[i] = 255;
    }
  }

  while(true){
    string s;
    cin >> s;

    if(s == "0") break;

    int r, g, b;
    r = stoi(s.substr(1,2), nullptr, 16);
    g = stoi(s.substr(3,2), nullptr, 16);
    b = stoi(s.substr(5,2), nullptr, 16);

    int ans = 0;
    int d = INF;
    REP(i,8){
      int tmp = calc_d(r, g, b, i);
      if(tmp < d){
        d = tmp;
        ans = i;
      }
    }
    cout << color[ans] << endl;
  }
  return 0;
}