Go: package main

import (
	"bufio"
	"os"
	"strings"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

type Color struct {
	name    string
	R, G, B int64
}

func main() {
	colors := []Color{
		{"black", 0, 0, 0},
		{"blue", 0, 0, 0xff},
		{"lime", 0, 0xff, 0},
		{"aqua", 0, 0xff, 0xff},
		{"red", 0xff, 0, 0},
		{"fuchsia", 0xff, 0, 0xff},
		{"yellow", 0xff, 0xff, 0},
		{"white", 0xff, 0xff, 0xff},
	}
	for scanner.Scan() {
		buf := strings.Split(scanner.Text(), "")
		if buf[0] == "0" {
			break
		}
		r, _ := strconv.ParseInt(strings.Join(buf[1:3], ""), 16, 64)
		g, _ := strconv.ParseInt(strings.Join(buf[3:5], ""), 16, 64)
		b, _ := strconv.ParseInt(strings.Join(buf[5:], ""), 16, 64)
		vmin := int64(3*0xff*0xff)
		var ans string
		for _, c := range colors {
			d := (r-c.R)*(r-c.R) + (g-c.G)*(g-c.G) + (b-c.B)*(b-c.B)
			if d < vmin {
				vmin = d
				ans = c.name
			}
		}
		fmt.Println(ans)
	}
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

int main()
{
	char* colors[] = { "black", "blue", "lime", "aqua"
		, "red", "fuchsia", "yellow", "white" };
	char buf[16];
	while (cin.getline(buf, sizeof(buf)), *buf != '0')
	{
		int r, g, b;
		sscanf(buf, "#%2x%2x%2x", &r, &g, &b);
		char* ans;
		double mind = 1e10;
		for (int i = 0; i < 8; ++i)
		{
			double rr = (i >> 2 & 1) * 0xff;
			double gg = (i >> 1 & 1) * 0xff;
			double bb = (i & 1) * 0xff;
			double d = sqrt((rr-r)*(rr-r) + (gg-g)*(gg-g) + (bb-b)*(bb-b));
			if (d < mind)
			{
				mind = d;
				ans = colors[i];
			}
		}
		puts(ans);
	}

	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
 
const int INF = 10000000;
 
int base16(char c) {
  if( 'a' <= c ) return c-'a'+10;
  else return c-'0';
}
 
int main() {
 
  string s;
 
  int coltabel[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 } };
 
  string nametable[8] = { "black", "blue", "lime", "aqua",
             "red", "fuchsia", "yellow", "white" };
 
  while(true) {
 
    cin>>s;
    if( s=="0" ) break;
 
    int r,g,b;
    r = base16(s[1])*16+base16(s[2]);
    g = base16(s[3])*16+base16(s[4]);
    b = base16(s[5])*16+base16(s[6]);
 
    int res,tmp=INF,t;
 
    for(int i=0; i<8; i++) {
      if( ( t = (r-coltabel[i][0])*(r-coltabel[i][0])
      + (g-coltabel[i][1])*(g-coltabel[i][1])
      + (b-coltabel[i][2])*(b-coltabel[i][2]) )
      < tmp ) {
    //cout<<t<<" "<<i<<endl;
    res = i;
    tmp = t;
      }
    }
 
    cout<<nametable[res]<<endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    string color[]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
    int colornum[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 value[200]={};
    for(int i=0;i<10;i++)value['0'+i]=i;
    for(int i=0;i<6;i++)value['a'+i]=10+i;
    string str;
    while(cin>>str&&str!="0"){
        int num[3];
        for(int i=0;i<3;i++)num[i]=value[str[1+2*i]]*16+value[str[2+2*i]];
        int ans[8]={};
        for(int i=0;i<8;i++){
            for(int j=0;j<3;j++)ans[i]+=pow(colornum[i][j]-num[j],2);
        }
        int co=0;
        for(int i=1;i<8;i++)if(ans[co]>ans[i])co=i;
        cout<<color[co]<<endl;
    }
}

C++: //41
#include<iostream>
#include<cstdlib>

#define S(X) ((X)*(X))

using namespace std;

int main(){
  for(char c[8];cin>>c,c[0]!='0';){
    int md=1<<30;
    int cn;
    unsigned cd=strtoul(c+1,0,16);
    for(int i=0;i<8;i++){
      unsigned d=0;
      for(int j=0;j<3;j++){
	static const unsigned cc[]={0x0,0xff,0xff00,0xffff,0xff0000,0xff00ff,0xffff00,0xffffff};
	d+=S((cd>>j*8&0xFF)-(cc[i]>>j*8&0xFF));
      }
      if(d<md){
	md=d;
	cn=i;
      }
    }
    const char *cstr[]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
    cout<<cstr[cn]<<endl;
  }
  return 0;
}

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

string s;
string color() {
	char l[6];
	for (int i = 0; i < 6; i++) {
		l[i] = s[i + 1];
	}
	int r, g, b;
	int z[6];
	for (int i = 0; i < 6; i++) {
		if (l[i] == '0') {
			z[i] = 0;
		}
		else if (l[i] == '1') {
			z[i] = 1;
		}
		else if (l[i] == '2') {
			z[i] = 2;
		}
		else if (l[i] == '3') {
			z[i] = 3;
		}
		else if (l[i] == '4') {
			z[i] = 4;
		}
		else if (l[i] == '5') {
			z[i] = 5;
		}
		else if (l[i] == '6') {
			z[i] = 6;
		}
		else if (l[i] == '7') {
			z[i] = 7;
		}
		else if (l[i] == '8') {
			z[i] = 8;
		}
		else if (l[i] == '9') {
			z[i] = 9;
		}
		else if (l[i] == 'a') {
			z[i] = 10;
		}
		else if (l[i] == 'b') {
			z[i] = 11;
		}
		else if (l[i] == 'c') {
			z[i] = 12;
		}
		else if (l[i] == 'd') {
			z[i] = 13;
		}
		else if (l[i] == 'e') {
			z[i] = 14;
		}
		else if (l[i] == 'f') {
			z[i] = 15;
		}
	}
	r = z[0] * 16 + z[1];
	g = z[2] * 16 + z[3];
	b = z[4] * 16 + z[5];
	if (r <= 128) {
		if (g <= 128) {
			if (b <= 128) {
				return "black";
			}
			else {
				return "blue";
			}
		}
		else {
			if (b <= 128) {
				return "lime";
			}
			else {
				return "aqua";
			}
		}
	}
	else {
		if (g <= 128) {
			if (b <= 128) {
				return "red";
			}
			else {
				return "fuchsia";
			}
		}
		else {
			if (b <= 128) {
				return "yellow";
			}
			else{
				return "white";
			}
		}
	}
}

int main() {
	string g[1001];
	int x;
	for (int i = 0;; i++){
		cin >> s;
		if (s == "0") {
			x = i;
			break;
		}
		g[i] = color();
	}
	for (int i = 0; i < x; i++){
		cout << g[i] << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>

using namespace std;

struct Color{
	double r,g,b;
};

double sq( double a ){
	return a * a;
}

int main(int argc, char const* argv[])
{
	const char *color[] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};
	Color colorStrong[] = {{0,0,0},{0,0,255},{0,255,0},{0,255,255},{255,0,0},{255,0,255},{255,255,0},{255,255,255}};

	Color inputColor;
	int rgb;
	double d[8];
	char damy;

	while( cin >> damy && damy != '0' ){
		cin >> hex >> rgb;
		inputColor.r = rgb >> 16;
		inputColor.g = ( rgb >> 8 ) & 0xff;
		inputColor.b = rgb & 0xff;

		for( int i = 0;i < 8;i++ ){
			d[i] = sqrt( sq( inputColor.r - colorStrong[i].r ) + sq( inputColor.g - colorStrong[i].g ) + sq( inputColor.b - colorStrong[i].b ) );
		}

		double* answer = min_element( d, d + 8 );

		for( int i = 0;i < 8;i++ ){
			if( answer == &d[i] ){
				cout << color[i] << endl;
				break;
			}
		}
	}
	return 0;
}