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 <cstring>
#include <string>
using namespace std;

const int INF = 1 << 28;

int decimal(char a, char b) {
    int d;
    if (isdigit(a)) d += a - '0';
    else d += a - 'a' + 10;
    d *= 10;

    if (isdigit(b)) d += b - '0';
    else d += b - 'a' + 10;
    
    return d;
}

struct color_t {
    int r, g, b;
    color_t(int r=0, int g=0, int b=0) : r(r), g(g), b(b) {}
    color_t(string s) {
        r = decimal(s[1], s[2]);
        g = decimal(s[3], s[4]);
        b = decimal(s[5], s[6]);
    }
};

int square_distance(color_t a, color_t b) {
    return (a.r - b.r) * (a.r - b.r) + (a.g - b.g) * (a.g - b.g) + (a.b - b.b) * (a.b - b.b);
}

int main() {
    string color[8];
    color_t color_v[8];

    color[0] = "black";   color_v[0] = color_t("#000000");
    color[1] = "blue";    color_v[1] = color_t("#0000ff");
    color[2] = "lime";    color_v[2] = color_t("#00ff00");
    color[3] = "aqua";    color_v[3] = color_t("#00ffff");
    color[4] = "red";     color_v[4] = color_t("#ff0000");
    color[5] = "fuchsia"; color_v[5] = color_t("#ff00ff");
    color[6] = "yellow";  color_v[6] = color_t("#ffff00");
    color[7] = "white";   color_v[7] = color_t("#ffffff");

    string s;
    while (getline(cin, s)) {
        if (s == "0") break;
        color_t c(s);
        int min_sq_dist = INF;
        string min_dist_color_name;
        for (int i = 0; i < 8; i++) {
            int sq_dist = square_distance(color_v[i], c);
            if (min_sq_dist > sq_dist) {
                min_sq_dist = sq_dist;
                min_dist_color_name = color[i];
            }
        }
        cout << min_dist_color_name << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <climits>

int distsq(int r, int g, int b, int r_, int g_, int b_)
{
	return (r-r_)*(r-r_) + (g-g_)*(g-g_) + (b-b_)*(b-b_);
}

int main()
{
	std::string input;
	while (true) {
		getline(std::cin, input);
		if (input=="0") break;
		int r, g, b;
		r = std::stoi(input.substr(1,2), nullptr, 16);
		g = std::stoi(input.substr(3,2), nullptr, 16);
		b = std::stoi(input.substr(5,2), nullptr, 16);
		int min_d = INT_MAX;
		std::string res;
		if (min_d > distsq(r,g,b,0,0,0)) {
			min_d = distsq(r,g,b,0,0,0);
			res = "black";
		}
		if (min_d > distsq(r,g,b,0,0,255)) {
			min_d = distsq(r,g,b,0,0,255);
			res = "blue";
		}
		if (min_d > distsq(r,g,b,0,255,0)) {
			min_d = distsq(r,g,b,0,255,0);
			res = "lime";
		}
		if (min_d > distsq(r,g,b,0,255,255)) {
			min_d = distsq(r,g,b,0,255,255);
			res = "aqua";
		}
		if (min_d > distsq(r,g,b,255,0,0)) {
			min_d = distsq(r,g,b,255,0,0);
			res = "red";
		}
		if (min_d > distsq(r,g,b,255,0,255)) {
			min_d = distsq(r,g,b,255,0,255);
			res = "fuchsia";
		}
		if (min_d > distsq(r,g,b,255,255,0)) {
			min_d = distsq(r,g,b,255,255,0);
			res = "yellow";
		}
		if (min_d > distsq(r,g,b,255,255,255)) {
			min_d = distsq(r,g,b,255,255,255);
			res = "white";
		}
		std::cout << res << std::endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
long i,j,k;
string s,c[8]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
while(cin>>s){
if(s=="0")break;
k=0;
i=s[1]-48;if(s[1]>64)i-=7;
j=s[2]-48;if(s[2]>64)j-=7;
if(i*16+j>=128)k+=4;
i=s[3]-48;if(s[3]>64)i-=7;
j=s[4]-48;if(s[4]>64)j-=7;
if(i*16+j>=128)k+=2;
i=s[5]-48;if(s[5]>64)i-=7;
j=s[6]-48;if(s[6]>64)j-=7;
if(i*16+j>=128)k++;
cout<<c[k]<<endl;
}
return 0;
}

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

double dis(int r1,int r2,int g1,int g2,int b1,int b2){
  return sqrt( (r1-r2)*(r1-r2) + (g1-g2)*(g1-g2) + (b1-b2)*(b1-b2) );
}

int main(){
  string color,ans;
  int r,g,b;
  double dmin,tmp;

  while(1){
    cin >> color;
    if(color=="0")break;

    r = 0;
    if(color[1]-'0' < 10)r += 16*(color[1]-'0');
    else r += 16 * (color[1]-'a'+10);
    if(color[2]-'0' < 10)r += color[2]-'0';
    else r += color[2]-'a'+10;
    g = 0;
    if(color[3]-'0' < 10)g += 16*(color[3]-'0');
    else g += 16 * (color[3]-'a'+10);
    if(color[4]-'0' < 10)g += color[4]-'0';
    else g += color[4]-'a'+10;
    b = 0;
    if(color[5]-'0' < 10)b += 16*(color[5]-'0');
    else b += 16 * (color[5]-'a'+10);
    if(color[6]-'0' < 10)b += color[6]-'0';
    else b += color[6]-'a'+10;

    dmin = 510;
    tmp = dis(r,0,g,0,b,0);
    if(tmp < dmin){
      dmin = tmp;
      ans = "black";
    }
    tmp = dis(r,0,g,0,b,255);
    if(tmp < dmin){
      dmin = tmp;
      ans = "blue";
    }
    tmp = dis(r,0,g,255,b,0);
    if(tmp < dmin){
      dmin = tmp;
      ans = "lime";
    }
    tmp = dis(r,0,g,255,b,255);
    if(tmp < dmin){
      dmin = tmp;
      ans = "aqua";
    }
    tmp = dis(r,255,g,0,b,0);
    if(tmp < dmin){
      dmin = tmp;
      ans = "red";
    }
    tmp = dis(r,255,g,0,b,255);
    if(tmp < dmin){
      dmin = tmp;
      ans = "fuchsia";
    }
    tmp = dis(r,255,g,255,b,0);
    if(tmp < dmin){
      dmin = tmp;
      ans = "yellow";
    }
    tmp = dis(r,255,g,255,b,255);
    if(tmp < dmin){
      dmin = tmp;
      ans = "white";
    }

    cout << ans << endl;
  }
}