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<cmath>
using namespace std;
int main() {
	long long a[10], c = 1, d, e = 0;
	int b = 0;
	while (c <= 1000000000) {
		a[b] = c;
		b++;
		c *= 8;
	}
	while (cin >> d&&d != 0) {
		e = 0;
		int f = 0;
		for (int i = b-1; i >= 0; i--) {
			f = 0;
			if (a[i] <= d) {
				while (a[i] <= d) {
					f++;
					d -= a[i];
				}
				if (f <= 3)
					e += (pow(10, i)*f);
				else if (f == 5)
					e += (pow(10, i)*(f + 2));
				else if (f < 6)
					e += (pow(10, i)*(f + 1));
				else if(f>=6)
					e += (pow(10, i)*(f + 2));
			}
		}
		cout << e << endl;
	}
}

C++: #include<iostream>
#include<string>
using namespace std;
int main() {
	string a;
	string c[8] = { "black","blue","lime","aqua","red","fuchsia","yellow","white" };
	int d[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} };
	while (cin>>a&&a!="0")
	{
		int t[3];
		for (int i = 1; i < a.length(); i += 2) {
			int b = 0;
			for (int j = 0; j <= 1; j++) {
				if ((int)a[i + j] >= '0' && (int)a[i +j] <= '9')
					b += (pow(16, (j+1)%2)*(int)(a[i +j] - '0'));
				else 
					b += (pow(16, (j+1)%2)*(10 + (int)a[i + j] - 'a'));
			}
			t[(i - 1) / 2] = b;
		}
		double e = 100000;
		string f = "";
		for (int i = 7; i >= 0; i--) {
			double g = sqrt(pow((t[0] - d[i][0]), 2) + pow((t[1] - d[i][1]), 2) + pow((t[2] - d[i][2]), 2));
			if (g <= e) {
				e = g;
				f = c[i];
			}
		}
		cout << f << endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>

using namespace std;

class RGBc{
public:
	int R,G,B;
	string name;

	RGBc();
	RGBc(int R_,int G_,int B_){
		R=R_;
		G=G_;
		B=B_;
	}

	bool operator<(const RGBc &rgb)const{
		return rgb.R>this->R;
	}
};

int main(){
	
	//map<RGB,string>table;
	vector<RGBc> vrgb;
	RGBc tmp(0,0,0);

	tmp.name="black";
	tmp.R=0;
	tmp.G=0;
	tmp.B=0;
	vrgb.push_back(tmp);

	tmp.name="blue";
	tmp.R=0;
	tmp.G=0;
	tmp.B=255;
	vrgb.push_back(tmp);

	tmp.name="lime";
	tmp.R=0;
	tmp.G=255;
	tmp.B=0;
	vrgb.push_back(tmp);

	tmp.name="aqua";
	tmp.R=0;
	tmp.G=255;
	tmp.B=255;
	vrgb.push_back(tmp);

	tmp.name="red";
	tmp.R=255;
	tmp.G=0;
	tmp.B=0;
	vrgb.push_back(tmp);

	tmp.name="fuchsia";
	tmp.R=255;
	tmp.G=0;
	tmp.B=255;
	vrgb.push_back(tmp);

	tmp.name="yellow";
	tmp.R=255;
	tmp.G=255;
	tmp.B=0;
	vrgb.push_back(tmp);

	tmp.name="white";
	tmp.R=255;
	tmp.G=255;
	tmp.B=255;
	vrgb.push_back(tmp);

	//table["black"].R=0;
	//table["black"].G=0;
	//table["black"].B=0;

	//table["blue"]=RGB(0,0,255);
	//table["lime"]=RGB(0,255,0);
	//table["aqua"]=RGB(0,255,255);
	//table["red"]=RGB(255,0,0);
	//table["fuchsia"]=RGB(255,0,255);
	//table["yellow"]=RGB(255,255,0);
	//table["white"]=RGB(255,255,255);

	string str;
	while(cin>>str&&str!="0"){
		vector<int> v;
		for(int i = 1; i < str.size(); i+=2){
			int num=0;
			if(str[i]>='a'&&str[i]<='f'){
				num+=str[i]-'a'+10;
				num*=16;
			}
			else{
				num+=str[i]-'0';
				num*=16;
			}
			if(str[i+1]>='a'&&str[i+1]<='f'){
				num+=str[i+1]-'a'+10;
			}
			else{
				num+=str[i+1]-'0';
			}
			v.push_back(num);
		}

		int R=v[0];
		int G=v[1];
		int B=v[2];

		int minDk=10000000;
		string color;
		for(int i = 0; i < vrgb.size(); i++){
			int dk=(R-vrgb[i].R)*(R-vrgb[i].R)+(G-vrgb[i].G)*(G-vrgb[i].G)+(B-vrgb[i].B)*(B-vrgb[i].B);
			if(minDk>dk){
				minDk=dk;
				color=vrgb[i].name;
			}
		}
		cout<<color<<endl;
	}

	return 0;
}