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>
#include<string>

using namespace std;

int main(){

	string inp;
	string base = { "0123456789abcdef" };
	string scol[8] = { "black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white" };
	int icol[8][3] = { { 0, 0, 0 }, { 0, 0, 256 }, { 0, 256, 0 }, { 0, 256, 256 }, { 256, 0, 0 }, { 256, 0, 256 }, { 256, 256, 0 }, { 256, 256, 256 } };
	int r, g, b;
	int ans;
	double ansnum;

	while (1){

		cin >> inp;
		if (inp == "0") break;

		r = base.find(inp[2]) * 1 + base.find(inp[1]) * 16;
		g = base.find(inp[4]) * 1 + base.find(inp[3]) * 16;
		b = base.find(inp[6]) * 1 + base.find(inp[5]) * 16;

		ans = 0;
		ansnum = sqrt(pow(r - icol[0][0], 2.0) + pow(g - icol[0][1], 2.0) + pow(b - icol[0][2], 2.0));
		for (int i = 1; i < 8; i++){
			if (ansnum>sqrt(pow(r - icol[i][0], 2.0) + pow(g - icol[i][1], 2.0) + pow(b - icol[i][2], 2.0))){
				ans = i;
				ansnum = sqrt(pow(r - icol[i][0], 2.0) + pow(g - icol[i][1], 2.0) + pow(b - icol[i][2], 2.0));
			}
		}

		cout << scol[ans] << endl;

	}
}

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

using namespace std;

string s[8] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};

int main(){
	
	string str;
	
	while(true){
		cin >> str;
		if(str[0] == '0'){
			break;
		}
		int ans = 0;
		if(str[1] < '0' || str[1] > '7'){
			ans += 4;
		}
		if(str[3] < '0' || str[3] > '7'){
			ans += 2;
		}
		if(str[5] < '0' || str[5] > '7'){
			ans += 1;
		}
		cout << s[ans] << endl;
	}
	
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;

int d[2] = { 0,255 };
int b(char c) {
	if (c <= '9')return c - '0';
	return c - 'a' + 10;
}
int c(string d) {
	return b(d[0]) * 16 + b(d[1]);
}
int main() {
	string a;
	while (cin >> a, a != "0") {
		int o = 0, p = 0, q = 0;
		int x = c(a.substr(1, 2)), y = c(a.substr(3, 2)), z = c(a.substr(5, 2));
		int MIN = 1 << 29;
		for (int e = 0; e < 2; e++) {
			for (int f = 0; f < 2; f++) {
				for (int g = 0; g < 2; g++) {
					if ((x - d[e])*(x - d[e]) + (y - d[f])*(y - d[f]) + (z - d[g])*(z - d[g]) < MIN) {
						MIN = (x - d[e])*(x - d[e]) + (y - d[f])*(y - d[f]) + (z - d[g])*(z - d[g]);
						o = e; p = f; q = g;
					}
				}
			}
		}
		if (o) {
			if (p) {
				if (q) {
					puts("white");
				}
				else {
					puts("yellow");
				}
			}
			else {
				if (q) {
					puts("fuchsia");
				}
				else {
					puts("red");
				}
			}
		}
		else {
			if (p) {
				if (q) {
					puts("aqua");
				}
				else {
					puts("lime");
				}
			}
			else {
				if (q) {
					puts("blue");
				}
				else {
					puts("black");
				}
			}
		}
	}
}

C++: #include<iostream>
#include<map>
#include<math.h>

using namespace std;

map<int, int> MR;
map<int, int> MG;
map<int, int> MB;

void make(){
  MR[0] = 0;
  MG[0] = 0;
  MB[0] = 0;
  MR[1] = 0;
  MG[1] = 0;
  MB[1] = 255;
  MR[2] = 0;
  MG[2] = 255;
  MB[2] = 0;
  MR[3] = 0;
  MG[3] = 255;
  MB[3] = 255;
  MR[4] = 255;
  MG[4] = 0;
  MB[4] = 0;
  MR[5] = 255;
  MG[5] = 0;
  MB[5] = 255;
  MR[6] = 255;
  MG[6] = 255;
  MB[6] = 0;
  MR[7] = 255;
  MG[7] = 255;
  MB[7] = 255;
}

int main(){

  make();

  char in[2];
  int status = 0;

  while(cin >> in[0]){
    if(in[0] == '0') break;

    int r, g, b;

    for(int i = 0; i < 3; i++){
      
      cin >> in[0] >> in[1];

      for(int j = 0; j <= 1; j++){
	if(in[j] == 'a') in[j] -= 39;
	if(in[j] == 'b') in[j] -= 39;
	if(in[j] == 'c') in[j] -= 39;
	if(in[j] == 'd') in[j] -= 39;
	if(in[j] == 'e') in[j] -= 39;
	if(in[j] == 'f') in[j] -= 39;
      }

      if(i == 0) r = (in[0] - 48) * 16 + (in[1] - 48);
      if(i == 1) g = (in[0] - 48) * 16 + (in[1] - 48);
      if(i == 2) b = (in[0] - 48) * 16 + (in[1] - 48);
    }

    double d;
    int min, then;

    for(int j = 0; j < 8; j++){
      d = sqrt((r - MR[j])*(r - MR[j])+(g - MG[j])*(g - MG[j])+(b - MB[j])*(b - MB[j]));
      if(j == 0 || min > d){
	min = d;
	then = j;
      }
    }

    if(then == 0) cout << "black" <<endl;
    if(then == 1) cout << "blue" <<endl;
    if(then == 2) cout << "lime" <<endl;
    if(then == 3) cout << "aqua" <<endl;
    if(then == 4) cout << "red" <<endl;
    if(then == 5) cout << "fuchsia" <<endl;
    if(then == 6) cout << "yellow" <<endl;
    if(then == 7) cout << "white" <<endl;

  }
  return 0;
}

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

using namespace std;

string colors[8] = {
  "black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"
};

int c(char ch) {
  if(isdigit(ch)) return ch-'0';
  return ch-'a'+10;
}

int main() {
  
  int colR[8];
  int colG[8];
  int colB[8];
  
  for(int i=0; i<8; i++) {
    colR[i] = i & 1 ? 255 : 0;
    colG[i] = i & 2 ? 255 : 0;
    colB[i] = i & 4 ? 255 : 0;
  }
  
  string s;
  
  while(cin >> s) {
    if(s == "0") break;
    
    s = s.substr(1);
    
    int R = (c(s[0]))*16 + (c(s[1]));
    int G = (c(s[2]))*16 + (c(s[3]));
    int B = (c(s[4]))*16 + (c(s[5]));
    
    int minD = (int)1e9;
    int id = -1;
    for(int i=0; i<8; i++) {
      if( minD > pow(R-colR[i],2.0) + pow(G-colG[i],2.0) + pow(B-colB[i],2.0) ) {
	id = i;
	minD = pow(R-colR[i],2.0) + pow(G-colG[i],2.0) + pow(B-colB[i],2.0);
      }
    }
    
    cout << colors[id] << endl;
  }
  
  return 0;
}