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 <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) {
    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 = "brack";
    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 = "yello";
    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;
  }
}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

vector<vector<int>> rgb = {
  {0, 0, 0},
  {0, 0, 255},
  {0, 255, 0},
  {0, 255, 255},
  {255, 0, 0},
  {255, 0, 255},
  {255, 255, 0},
  {255, 255, 255}
};
vector<string> name = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  auto f = [&](string s) { return (isdigit(s[0]) ? s[0] - '0' : s[0] - 'a' + 10) * 16 + (isdigit(s[1]) ? s[1] - '0' : s[1] - 'a' + 10); };
  string s;
  while (cin >> s, s != "0") {
    int r = f(s.substr(1, 2)), g = f(s.substr(3, 2)), b = f(s.substr(5, 2));
    double d_min = 1e9;
    string ans = "";
    for (int i = 0; i < 8; i++) {
      double d = sqrt(pow(r - rgb[i][0], 2.0) + pow(g - rgb[i][1], 2.0) + pow(b - rgb[i][2], 2.0));
      if (d < d_min) {
        d_min = d;
        ans = name[i];
      }
    }
    cout << ans << endl;
  }

  return 0;
}

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

string near(int R, int G, int B);

double dist(int R1, int G1, int B1, int R2, int G2, int B2);

int main(void){
  map<char,int> d;
  for(int i=0;i<10;i++){
    d[i+'0']=i;
  }
  for(int i=0;i<6;i++){
    d[i+'a']=i+10;
  }
  string s;
  int R,G,B;
  while(1){
    cin>>s;
    if(s=="0")break;
    R=d[s[1]]*16+d[s[2]];
    G=d[s[3]]*16+d[s[4]];
    B=d[s[5]]*16+d[s[6]];
    cout<<near(R,G,B)<<endl;
  }
  return 0;
}

string near(int R, int G, int B){
  double distance=10000;
  string color="hoge";
  if(dist(R,G,B,0,0,0)<distance){
    color="black";
    distance=dist(R,G,B,0,0,0);
  }
  if(dist(R,G,B,0,0,255)<distance){
    color="blue";
    distance=dist(R,G,B,0,0,255);
  }
  if(dist(R,G,B,0,255,0)<distance){
    color="lime";
    distance=dist(R,G,B,0,255,0);
  }
  if(dist(R,G,B,0,255,255)<distance){
    color="aqua";
    distance=dist(R,G,B,0,255,255);
  }
  if(dist(R,G,B,255,0,0)<distance){
    color="red";
    distance=dist(R,G,B,255,0,0);
  }
  if(dist(R,G,B,255,0,255)<distance){
    color="fuchsia";
    distance=dist(R,G,B,255,0,255);
  }
  if(dist(R,G,B,255,255,0)<distance){
    color="yellow";
    distance=dist(R,G,B,255,255,0);
  }
  if(dist(R,G,B,255,255,255)<distance){
    color="white";
    distance=dist(R,G,B,255,255,255);
  }
  return color;
}

double dist(int R1, int G1, int B1, int R2, int G2, int B2){
  return sqrt((R1-R2)*(R1-R2)+(G1-G2)*(G1-G2)+(B1-B2)*(B1-B2));
}

C++: #include<bits//stdc++.h>
using namespace std;
string s, x[2][2][2] = { {{"black","blue"}, {"lime","aqua"}}, { {"red","fuchsia"}, {"yellow","white"} } },T = "89abcdef";
int main() {
	while (1) {
		int a = 0, b = 0, c = 0;cin >> s;
		if (s == "0") { break; }
		for (int i = 0; i < 8; i++) if (T[i] == s[1]) a++;
		for (int i = 0; i < 8; i++) if (T[i] == s[3]) b++;
		for (int i = 0; i < 8; i++) if (T[i] == s[5]) c++;
		cout << x[a][b][c] << endl;
	}
}