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 <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;

}

C++: #include<iostream>
#include<cmath>
#include<string>

using namespace std;

int main(){

	string inp;
	string base = ("0123456789abcdef" );
	string scol[8] = { "black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white" };
	int icol[8][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 } };
	int r, g, b;
	int ans;
	double ansnum;

	while (1){

		cin >> inp;
		if (inp == "0") break;

		r = base.find(inp[2]) * 1 + base.find(inp[1]) * 16;
		g = base.find(inp[4]) * 1 + base.find(inp[3]) * 16;
		b = base.find(inp[6]) * 1 + base.find(inp[5]) * 16;

		ans = 0;
		ansnum = pow(r - icol[0][0], 2.0) + pow(g - icol[0][1], 2.0) + pow(b - icol[0][2], 2.0);
		for (int i = 1; i < 8; i++){
			if (ansnum>pow(r - icol[i][0], 2.0) + pow(g - icol[i][1], 2.0) + pow(b - icol[i][2], 2.0)){
				ans = i;
				ansnum = pow(r - icol[i][0], 2.0) + pow(g - icol[i][1], 2.0) + pow(b - icol[i][2], 2.0);
			}
		}

		cout << scol[ans] << endl;

	}
}

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 <= 127) {
		if (g <= 127) {
			if (b <= 127) {
				return "black";
			}else {
				return "blue";
			}
		}else if (b <= 127) {
				return "lime";
			  }else {
				return "aqua";
			  }
	}
	else if (g <= 127) {
			if (b <= 127) {
				return "red";
			}else{
				return "fuchsia";
			}
		}
		else if (b <= 127) {
				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;
	}
	char c;
	cin >> c;
	return 0;
}

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[6]-'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 <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'));
    }
  }
  
  int dk = 1 << 28, l = -1;
  rep (S,8) {
    int ar[3], temp = 0;
    rep (i,3) ar[i] = (S >> i & 1) ? 255 : 0 ;
    rep (i,3) temp += abs(ar[i] - my[i]);
    if (dk > temp) {
      dk = temp;
      l = S;
    }
  }
  return name[l];
}

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