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
}

Python: colors = {}
colors['black'] = [0, 0, 0]
colors['blue'] = [0, 0, 255]
colors['lime'] = [0, 255, 0]
colors['aqua'] = [0, 255, 255]
colors['red'] = [255, 0, 0]
colors['fuchsia'] = [255, 0, 255]
colors['yellow'] = [255, 255, 0]
colors['white'] = [255, 255, 255]

while True:
    color = input()
    if color == '0':
        break
    r, g, b = (int(color[1:3], 16),
               int(color[3:5], 16),
               int(color[5:7], 16))
    print(r, g, b)
    near_color = ['', float('inf')]
    for k, v in colors.items():
        dk = ((v[0] - r) ** 2 +
              (v[1] - g) ** 2 +
              (v[2] - b) ** 2) ** .5
        if dk < near_color[1]:
            near_color = [k, dk]
    print(near_color[0])

Python: INF = 10 ** 10
dic = {}
for i in range(10):
  dic[str(i)] = i
for i in range(ord("a"), ord("f") + 1):
  dic[chr(i)] = i - ord("a") + 10

def hex_to_dec(s):
  return dic[s[0]] * 16 + dic[s[1]]

colors = [("black",   list(map(hex_to_dec, ["00", "00", "00"]))),
          ("blue",    list(map(hex_to_dec, ["00", "00", "ff"]))),
          ("lime",    list(map(hex_to_dec, ["00", "ff", "00"]))),
          ("aqua",    list(map(hex_to_dec, ["00", "ff", "ff"]))),
          ("red",     list(map(hex_to_dec, ["ff", "00", "00"]))),
          ("fuchsia", list(map(hex_to_dec, ["ff", "00", "ff"]))),
          ("yellow",  list(map(hex_to_dec, ["ff", "ff", "00"]))),
          ("white",   list(map(hex_to_dec, ["ff", "ff", "ff"])))]

while True:
  s = input()
  if s == "0":
    break
  r, g, b = map(hex_to_dec, [s[1:3], s[3:5], s[5:7]])
  lowest_name = "KUWA"
  lowest_score = INF
  for name, rgb in colors:
    rc, gc, bc = rgb
    score = (r - rc) ** 2 + (g - gc) ** 2 + (b - bc) ** 2
    if score < lowest_score:
      lowest_name, lowest_score = name, score
  print(lowest_name)

Python: import math

def solve(line):
	R = int(line[1:3], 16)
	G = int(line[3:5], 16)
	B = int(line[5:7], 16)
	
	sa_black = math.sqrt(R**2 + G**2 + B**2)
	sa_max = sa_black
	ans_color = "black"
	
	sa_blue = math.sqrt(R**2 + G**2 + (B - 255)**2)
	if sa_blue < sa_max:
		sa_max = sa_blue
		ans_color = "blue"
	
	sa_lime = math.sqrt(R**2 + (G - 255)**2 + B**2)
	if sa_lime < sa_max:
		sa_max = sa_lime
		ans_color = "lime"
	
	sa_aqua = math.sqrt(R**2 + (G - 255)**2 + (B - 255)**2)
	if sa_aqua < sa_max:
		sa_max = sa_aqua
		ans_color = "aqua"
	
	sa_red = math.sqrt((R - 255)**2 + G**2 + B**2)
	if sa_red < sa_max:
		sa_max = sa_red
		ans_color = "red"
	
	sa_fuchsia = math.sqrt((R - 255)**2 + G**2 + (B - 255)**2)
	if sa_fuchsia < sa_max:
		sa_max = sa_fuchsia
		ans_color = "fuchsia"
	
	sa_yellow = math.sqrt((R - 255)**2 + (G - 255)**2 + B**2)
	if sa_yellow < sa_max:
		sa_max = sa_yellow
		ans_color = "blue"
	
	sa_white = math.sqrt((R - 255)**2 + (G - 255)**2 + (B - 255)**2)
	if sa_white < sa_max:
		sa_max = sa_white
		ans_color = "white"

	return ans_color

while True:
	line = input()
	if line == '0': break
	print(solve(line))

C++: #include<iostream>
#include<string>
#include<stdio.h>
using namespace std;

int main(){

string st;
int Z[][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}};

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


int k[3]={};
int n[10]={};
for(int i=1;i<7;i++){
n[i]=st[i]-'0';
if(st[i]=='a')n[i]=10;
if(st[i]=='b')n[i]=11;
if(st[i]=='c')n[i]=12;
if(st[i]=='d')n[i]=13;
if(st[i]=='e')n[i]=14;
if(st[i]=='f')n[i]=15;
}

k[0]=n[1]*16+n[2];
k[1]=n[3]*16+n[4];
k[2]=n[5]*16+n[6];

int N[10]={};int min=90000;int t=0;
for(int i=0;i<8;i++)
{
N[i]=(Z[i][0]-k[0])*(Z[i][0]-k[0])+(Z[i][1]-k[1])*(Z[i][1]-k[1])+(Z[i][2]-k[2])*(Z[i][2]-k[2]);
if(min>N[i]){t=i;min=N[i];}
//cout<<N[i]<<endl;
}
if(t==0)cout<<"black";
if(t==1)cout<<"blue";
if(t==2)cout<<"lime";
if(t==3)cout<<"aqua";
if(t==4)cout<<"red";
if(t==5)cout<<"fuchsia";
if(t==6)cout<<"yellow";
if(t==7)cout<<"white";
cout<<endl;


}
return 0;
}

C++: #include<iostream>
#include<string>
#include<cstring>
#include<cctype>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define INF 1e6
using namespace std;

int d(string s,int color[3]){
  int red=0,blue=0,green=0;
  if(!isdigit(s[1]))red+=(s[1]-'a'+10)*16;
  else red+=(s[1]-'0')*16;
  if(!isdigit(s[2]))red+=(s[2]-'a'+10);
  else red+=(s[2]-'0');
  if(!isdigit(s[3]))green+=(s[3]-'a'+10)*16;
  else green+=(s[3]-'0')*16;
  if(!isdigit(s[4]))green+=(s[4]-'a'+10);
  else green+=(s[4]-'0');
  if(!isdigit(s[5]))blue+=(s[5]-'a'+10)*16;
  else blue+=(s[5]-'0')*16;
  if(!isdigit(s[6]))blue+=(s[6]-'a'+10);
  else blue+=(s[6]-'0');
  return pow((red-color[0]),2)+pow((green-color[1]),2)+pow((blue-color[2]),2);
}

int cl[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 main(){
  string str;
  while(1){
    cin>>str;
    if(str=="0")break;
    int num=INF;
    string ans="";
    rep(i,8){
      if(num>d(str,cl[i])){
	if(i==0)ans="black";
	else if(i==1)ans="blue";
	else if(i==2)ans="lime";
	else if(i==3)ans="aqua";
	else if(i==4)ans="red";
	else if(i==5)ans="fuchsia";
	else if(i==6)ans="yellow";
	else if(i==7)ans="white";
	num=d(str,cl[i]);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}