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 <cctype>
#include <cmath>

using namespace std;

string Strength[8] = {"000000","0000ff","00ff00","00ffff",
		      "ff0000","ff00ff","ffff00","ffffff"};

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

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

int change(string s){
  return x_t(s[0])*16 + x_t(s[1]);
}

string solve(string R,string G,string B){
  int pos,Min = (1<<29),d;
  int r = change(R),g = change(G),b = change(B);
  string rr,gg,bb;

  for(int i = 0 ; i < 8 ; i++){
    rr = Strength[i].substr(0,2);
    gg = Strength[i].substr(2,2);
    bb = Strength[i].substr(4,2);
 
    int rk = change(rr) ,gk = change(gg) ,bk = change(bb);    
    d = sqrt((r-rk)*(r-rk) + (g-gk)*(g-gk) + (b-bk)*(b-bk));

    if(d < Min){
      Min = d;
      pos = i;
    }
  }

  return Color[pos];
}

int main(){
  string str;

  while(cin >> str ,str != "0"){
    string R,G,B;

    R = str.substr(1,2);
    G = str.substr(3,2);
    B = str.substr(5,2);

    cout << solve(R,G,B) << endl;
  }

  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,string> P;
#define INF (1<<20)

typedef struct {
  string name; // ??????
  string R; // ???
  string G; // ???
  string B; // ???
} color; // ???????§???????

color data[8]=
  {{"black","00","00","00"},
   {"blue","00","00","ff"},
   {"lime","00","ff","00"},
   {"aqua","00","ff","ff"},
   {"red","ff","00","00"},
   {"fuchsia","ff","00","ff"},
   {"yellow","ff","ff","00"},
   {"white","ff","ff","ff"}
  };

int trans(string num){
  int sum = 0;
  if(num[0] >= 'a' && num[0] <= 'f') sum = (num[0] - 'a' + 10)*16;
  else sum = (num[0] - '0')*16;
  if(num[1] >= 'a' && num[1] <= 'f') sum += (num[1] - 'a' + 10);
  else sum += (num[1] - '0');
  return sum;
}

int main(){
  string str;
  int RGB[8][3];
  for(int i=0;i<8;i++){
    RGB[i][0] = trans(data[i].R);
    RGB[i][1] = trans(data[i].G);
    RGB[i][2] = trans(data[i].B);
  }
  while(cin >> str , str!="0"){
    string red = str.substr(1,2);
    string green = str.substr(3,2);
    string blue = str.substr(5,2);
    int r = trans(red);
    int g = trans(green);
    int b = trans(blue);
    double ans = INF;
    int pos = 0;
    for(int i=0;i<8;i++){
      double tr = (r-RGB[i][0])*(r-RGB[i][0]);
      double tg = (g-RGB[i][1])*(g-RGB[i][1]);
      double tb = (b-RGB[i][2])*(b-RGB[i][2]);
      double tmp = sqrt(tr+tg+tb);
      if(ans > tmp){
	ans = tmp;
	pos = i;
      }
    }
    cout << data[pos].name << endl;
  }
}

C++: import java.util.Scanner;
import static java.lang.System.out;
class Main{
  public static void main(String args[]){
    Scanner scan = new Scanner(System.in);
    String name[] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};
    int color[][] = {{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(true){
      String str = scan.next();
      if(str.equals("0")) break;

      int R = Integer.parseInt(str.substring(1,3),16);
      int G = Integer.parseInt(str.substring(3,5),16);
      int B = Integer.parseInt(str.substring(5,7),16);
      double min = Double.MAX_VALUE;
      int Index = 0;
      for(int i = 0 ; i < 8 ; i++){
        double near = Math.sqrt(Math.pow(R - color[i][0],2) + Math.pow(G - color[i][1],2) + Math.pow(B - color[i][2],2));
        if( near < min ){
          min = near;
          Index = i;
        }
      }
      out.println(name[Index]);
    }
  }
}

C++: #include<iostream>
#include<cstdlib>
#include<cstdio>
#define w 15*16+15
using namespace std;
int fld[8][3]={0,0,0,0,0,w,0,w,
	0,0,w,w,w,0,0
	,w,0,w,w,w,0,w,w,w};
char* col[]={"black",
	"blue","lime","aqua",
	"red","fuchsia",
	"yellow","white"};
int main(){
	int temp,t,x,y,z,a[8],ren;
	char s[10];
	while(cin>>s,s[0]!='0'){
		temp=1000000;
		for(int i=1;i<8;i++){
			if(s[i]>'9')
			a[i-1]=9+s[i]-'a';
			else a[i-1]=s[i]-'0';
		}
		for(int i=0;i<8;i++){
			x=a[0]*16+a[1]-fld[i][0];
			y=a[2]*16+a[3]-fld[i][1];
			z=a[4]*16+a[5]-fld[i][2];
			ren=sqrt(x*x+y*y+z*z);
			if(ren<temp){
				t=i;
				temp=ren;
			}
		}cout<<col[t]<<endl;
	}
	return 0;
}

C++: #include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 
#define sq(a) ((a)*(a))

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main()
{
	char str[8];
	while(scanf("%s", str), str[0]!='0'){
		int v;
		sscanf(str+1, "%x", &v);
		int r = v / 0x10000;
		int g = (v % 0x10000) / 0x100;
		int b =  v % 0x100;
		
		const int rs[] = {0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff};
		const int gs[] = {0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff};
		const int bs[] = {0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff};
		
		int bestid = 0;
		int best = 1<<29;
		rep(i, 8){
			int d = sq(r-rs[i])+sq(g-gs[i])+sq(b-bs[i]);
			if(d < best){
				best = d;
				bestid = i;
			}
		}
		
		const char* name[] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
		puts(name[bestid]);
	}
	
	return 0;
}