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

const char* color[] = {
	"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"
};

const int RGB[][ 3 ] = {
	{ 0, 0, 0 }, { 0, 0, 255 }, { 0, 255, 255 },
	{ 0, 255, 255 }, { 255, 0, 0 }, { 255, 0, 255 },
	{ 255, 255, 0 }, { 255, 255, 255 },
};

int xtod( char* c )
{
	int ret = 0;
	int mag = 16;
	for( int i = 0; i < 2; ++i, ++c ){
		int d = 0;
		if( *c >= '0' && *c <= '9' ){
			d = *c - '0';
		}else{
			d = *c - 'a' + 10;
		}
		ret += ( d * mag );
		mag /= 16;
	}
	return ret;
}

int distance( const int* o, int* x )
{
	int dd[ 3 ];
	for( int i = 0; i < 3; ++i ){
		dd[ i ] = x[ i ] - o[ i ];
		dd[ i ] *= dd[ i ];
	}
	return dd[ 0 ] + dd[ 1 ] + dd[ 2 ];
}

int main()
{
	char col[ 8 ];

	while( cin >> col && *col != '0' ){
		int n[ 3 ];
		for( int i = 0; i < 3; ++i ){
			n[ i ] = xtod( col + ( 1 + i * 2 ) );
		}
		int d[ 8 ];
		for( int i = 0; i < 8; ++i ){
			d[ i ] = distance( RGB[ i ], n );
		}
		int ans = 0;
		int ansD = 200000;
		for( int i = 0; i < 8; ++i ){
			if( d[ i ] < ansD ){
				ans = i;
				ansD = d[ i ];
			}
		}
		cout << color[ ans ] << endl;
	}

	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

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

bool is_digit(char c) { return '0' <= c && c <= '9'; }
int c2i(char c) { return c - '0'; }

string solve() {
  in.erase(0, 1);
  int my[3];
  rep (i,3) my[i] = 0;
  rep (i,3) {
    if (is_digit(in[i*2])) {
      my[i] = c2i(in[i*2]) * 16;
    } else {
      my[i] = (10 + (in[i*2] - 'a')) * 16;
    }
    
    if (is_digit(in[i*2+1])) {
      my[i] += c2i(in[i*2+1]);
    } else {
      my[i] += (10 + (in[i*2+1] - 'a'));
    }
  }
  
  double dk = double(1 << 28);
  int l = -1;
  rep (S,8) {
    int ar[3], temp = 0;
    for (int i = 2; i >= 0; --i) ar[i] = (S >> i & 1) ? 255 : 0 ;
    rep (i,3) {
      temp += (ar[i] - my[i]) * (ar[i] - my[i]);
    }
    double d = sqrt(double(temp));
    if (dk > d) {
      dk = d;
      l = S;
    }
  }
  return name[l];
}

int main() {
  while (cin >> in) {
    if (in == "0") break;
    cout << solve() << endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
string color[] = {"black", "blue", "lime", "aqua",
    "red", "fuchsia", "yellow", "white"};
int nums[][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 convert(string str) {
    int res = 0;
    if ('0'<=str[0]&&str[0]<='9') {
        res += (str[0]-'0') * 16;
    } else if ('a'<=str[0]&&str[0]<='f') {
        res += (str[0]-'a'+10) * 16;
    }
    if ('0'<=str[1]&&str[1]<='9') {
        res += (str[1]-'0');
    } else if ('a'<=str[1]&&str[1]<='f') {
        res += (str[1]-'a'+10);
    }
    return res;
}

int main() {
    string str;
    while (cin >> str) {
        if (str == "0") break;
        double d = 10000000.0;
        string res;
        int r = convert(str.substr(1,2)), g = convert(str.substr(3,2)), b = convert(str.substr(5,2));
        for (int i=0; i<8; i++) {
            double tmp = sqrt(pow(r-nums[i][0], 2)+pow(g-nums[i][1], 2)+pow(b-nums[i][2], 2));
            if (tmp < d) {
                d = tmp;
                res = color[i];
            }
        }
        cout << res << endl;
    }
}

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

const int INF = 1 << 28;

int decimal(char a, char b) {
    int d;
    if (isdigit(a)) d += a - '0';
    else d += a - 'a' + 10;
    d *= 10;

    if (isdigit(b)) d += b - '0';
    else d += b - 'a' + 10;
    
    return d;
}

struct color_t {
    int r, g, b;
    color_t(int r=0, int g=0, int b=0) : r(r), g(g), b(b) {}
    color_t(string s) {
        r = decimal(s[1], s[2]);
        g = decimal(s[3], s[4]);
        b = decimal(s[5], s[6]);
    }
};

int square_distance(color_t a, color_t b) {
    return (a.r - b.r) * (a.r - b.r) + (a.g - b.g) * (a.g - b.g) + (a.b - b.b) * (a.b - b.b);
}

int main() {
    string color[8];
    color_t color_v[8];

    color[0] = "black";   color_v[0] = color_t("#000000");
    color[1] = "blue";    color_v[1] = color_t("#0000ff");
    color[2] = "lime";    color_v[2] = color_t("#00ff00");
    color[3] = "aqua";    color_v[3] = color_t("#00ffff");
    color[4] = "red";     color_v[4] = color_t("#ff0000");
    color[5] = "fuchsia"; color_v[5] = color_t("#ff00ff");
    color[6] = "yellow";  color_v[6] = color_t("#ffff00");
    color[7] = "white";   color_v[7] = color_t("#ffffff");

    string s;
    while (getline(cin, s)) {
        if (s == "0") break;
        color_t c(s);
        int min_sq_dist = INF;
        string min_dist_color_name;
        for (int i = 0; i < 8; i++) {
            int sq_dist = square_distance(color_v[i], c);
            if (min_sq_dist > sq_dist) {
                min_sq_dist = sq_dist;
                min_dist_color_name = color[i];
            }
        }
        cout << min_dist_color_name << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <climits>

int distsq(int r, int g, int b, int r_, int g_, int b_)
{
	return (r-r_)*(r-r_) + (g-g_)*(g-g_) + (b-b_)*(b-b_);
}

int main()
{
	std::string input;
	while (true) {
		getline(std::cin, input);
		if (input=="0") break;
		int r, g, b;
		r = std::stoi(input.substr(1,2), nullptr, 16);
		g = std::stoi(input.substr(3,2), nullptr, 16);
		b = std::stoi(input.substr(5,2), nullptr, 16);
		int min_d = INT_MAX;
		std::string res;
		if (min_d > distsq(r,g,b,0,0,0)) {
			min_d = distsq(r,g,b,0,0,0);
			res = "black";
		}
		if (min_d > distsq(r,g,b,0,0,255)) {
			min_d = distsq(r,g,b,0,0,255);
			res = "blue";
		}
		if (min_d > distsq(r,g,b,0,255,0)) {
			min_d = distsq(r,g,b,0,255,0);
			res = "lime";
		}
		if (min_d > distsq(r,g,b,0,255,255)) {
			min_d = distsq(r,g,b,0,255,255);
			res = "aqua";
		}
		if (min_d > distsq(r,g,b,255,0,0)) {
			min_d = distsq(r,g,b,255,0,0);
			res = "red";
		}
		if (min_d > distsq(r,g,b,255,0,255)) {
			min_d = distsq(r,g,b,255,0,255);
			res = "fuchsia";
		}
		if (min_d > distsq(r,g,b,255,255,0)) {
			min_d = distsq(r,g,b,255,255,0);
			res = "yellow";
		}
		if (min_d > distsq(r,g,b,255,255,255)) {
			min_d = distsq(r,g,b,255,255,255);
			res = "white";
		}
		std::cout << res << std::endl;
	}
	return 0;
}