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 <cmath>
using namespace std;

int checkHeight(double h);
const string COLORS[8] = {"black", "blue", "lime", "aqua"
                         , "red", "fuchsia", "yellow", "white"};

const int RGB_VALUES[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 toDec(char s);

int main()
{
    while(1)
    {
        string in_str;
        cin >> in_str;
        if(in_str == "0")
        {
            break;
        }
        
        int r = toDec(in_str[1]) * 16 + toDec(in_str[2]);
        int g = toDec(in_str[3]) * 16 + toDec(in_str[4]);
        int b = toDec(in_str[5]) * 16 + toDec(in_str[6]);

        double dist_min = 1000000;
        int index = 0;
        for(int i = 0; i < 8; i++)
        {
            double dist_square = (r - RGB_VALUES[i][0]) * (r - RGB_VALUES[i][0])
                                 + (g - RGB_VALUES[i][1]) * (g - RGB_VALUES[i][1])
                                 + (b - RGB_VALUES[i][2]) * (b - RGB_VALUES[i][2]);
            if(isless(dist_square, dist_min))
            {
                dist_min = dist_square;
                index = i;
            }
        }
        cout << COLORS[index] << endl;
    }
    return 0;
}

int toDec(char s)
{
    int value;
    if(s >= '0' && s <= '9')
    {
       value = s - '0';
    }
    else
    {
        value = s - 'a' + 10;
    }
    return value;
}

C++: #include<cstdio>
#include<iostream>
#include<string>
using namespace std;
int main(){
  char c[10];
  int r,g,b,id;
  string str[8] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};
  while(scanf("%s",c),c[0]!='0'){
    r = g = b = 0;
    if('0'<=c[1] && c[1]<='9') r += (c[1]-'0')*16;
    else r += (c[1]-'A'+10)*16;
    if('0'<=c[2] && c[2]<='9') r += (c[2]-'0');
    else r += (c[2]-'A'+10);
    if('0'<=c[3] && c[3]<='9') g += (c[3]-'0')*16;
    else g += (c[3]-'A'+10)*16;
    if('0'<=c[4] && c[4]<='9') g += (c[4]-'0');
    else g += (c[4]-'A'+10);
    if('0'<=c[5] && c[5]<='9') b += (c[5]-'0')*16;
    else b += (c[5]-'A'+10)*16;
    if('0'<=c[6] && c[6]<='9') b += (c[2]-'0');
    else r += (c[6]-'A'+10);
    id = 0;
    if(r >=123) id += 4;
    if(g >=123) id += 2;
    if(b >=123) id += 1;
    cout << str[id] << endl;
  }
  return(0);
}

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

typedef long long ll;
typedef pair<int,string> pis;
vector<pis> v;

template<class T>
T sqr(T a) { return a * a; }

int main() {
	string s;

	v.push_back(pis(0x000000, "black"));
	v.push_back(pis(0x0000ff, "blue"));
	v.push_back(pis(0x00ff00, "lime"));
	v.push_back(pis(0x00ffff, "aqua"));
	v.push_back(pis(0xff0000, "red"));
	v.push_back(pis(0xff00ff, "fuchsia"));
	v.push_back(pis(0xffff00, "yellow"));
	v.push_back(pis(0xffffff, "white"));

	while(cin >> s, s[0]-'0') {
		int a = 0;
		for(int i = 0; i < 6; i++) {
			a *= 16;
			if(0 <= s[i+1] && s[i+1] <= '9')
				a += s[i+1] - '0';
			else
				a += s[i+1] - 'a' + 10;
		}

		int res = -1;
		ll mn = 1e9;
		for(int i = 0; i < v.size(); i++) {
			ll tmp = 0;
			for(int j = 0; j < 3; j++) {
				tmp += sqr(((v[i].first >> (j * 8)) & 0xff) - ((a >> (j * 8)) & 0xff));
			}
			if(tmp < mn) {
				mn = tmp;
				res = i;
			}
		}
		cout << v[res].second << endl;
	}
}

C++: #include <stdio.h>
#include <string.h>
#include <math.h>

double dist(int table[][3],int k,int rk,int gk,int bk) {

  return sqrt((table[k][0]-rk)*(table[k][0]-rk)+(table[k][1]-gk)*(table[k][1]-gk)+(table[k][2]-bk)*(table[k][2]-bk));

}

int main(void) {

  int rk,gk,bk;

  int table[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}};

  char buf[10];
  int color[10];

  double min;
  int ans;

  int i,k;


  while(1) {

    fgets(buf,sizeof(buf),stdin);

    buf[strlen(buf)-1]='\0';

    if(strcmp(buf,"0")==0) break;

    for(i=0;i<strlen(buf)-1;i++) {

      if(buf[i+1]>='0' && buf[i+1]<='9') color[i]=buf[i+1]-'0';

      else if(buf[i+1]=='a') color[i]=10;

      else if(buf[i+1]=='b') color[i]=11;

      else if(buf[i+1]=='c') color[i]=12;

      else if(buf[i+1]=='d') color[i]=13;
      
      else if(buf[i+1]=='e') color[i]=14;

      else if(buf[i+1]=='f') color[i]=15;

    }

    rk=16*color[0]+color[1];

    gk=16*color[2]+color[3];

    bk=16*color[4]+color[5];

    min=256.0;

    //printf("%d %d %d\n",rk,gk,bk);

    for(k=0;k<8;k++) {

      double temp;

      temp=dist(table,k,rk,gk,bk);

      if(min>temp) {

	min=temp;
	ans=k;

      }

    }

    //printf("%d\n",ans);

    switch(ans) {

    case 0:
      puts("black");
      break;

    case 1:
      puts("blue");
      break;

    case 2:
      puts("lime");
      break;

    case 3:
      puts("aqua");
      break;

    case 4:
      puts("red");
      break;

    case 5:
      puts("fuchsia");
      break;

    case 6:
      puts("yellow");
      break;
      
    case 7: 
      puts("white");
      break;

    }

  }

  return 0;

}