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 <cmath>
#include <vector>
#include <string>
#include <tuple>

int tsurai(int r, int g, int b) {
  return r*r + g*g + b*b;
}

int testcase_ends() {
  char c;
  scanf(" %c", &c);
  if (c == '0') return 1;

  int r, g, b;
  scanf("%2x%2x%2x", &r, &g, &b);

  std::vector<std::pair<std::string, std::tuple<int, int, int>>> col;
  int f = 255;
  
  col.emplace_back("black", std::make_tuple(0, 0, 0));
  col.emplace_back("blue", std::make_tuple(0, 0, f));
  col.emplace_back("lime", std::make_tuple(0, f, 0));
  col.emplace_back("aqua", std::make_tuple(0, f, f));
  col.emplace_back("red", std::make_tuple(f, 0, 0));
  col.emplace_back("fuchsia", std::make_tuple(f, 0, f));
  col.emplace_back("yellow", std::make_tuple(f, f, 0));
  col.emplace_back("white", std::make_tuple(f, f, f));

  int d = 1e9;
  std::string res;
  for (auto const& p: col) {
    std::string cur;
    std::tuple<int, int, int> rgb;
    std::tie(cur, rgb) = p;
    int r0, g0, b0;
    std::tie(r0, g0, b0) = rgb;

    int cur_d = tsurai(r0-r, g0-g, b0-b);
    if (d > cur_d) {
      d = cur_d;
      res = cur;
    }
  }
  printf("%s\n", res.c_str());
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}

C++: #include<iostream>
#include<map>
#include<math.h>

using namespace std;

map<int, int> MR;
map<int, int> MG;
map<int, int> MB;

void make(){
  MR[0] = 0;
  MG[0] = 0;
  MB[0] = 0;
  MR[1] = 0;
  MG[1] = 0;
  MB[1] = 255;
  MR[2] = 0;
  MG[2] = 255;
  MB[2] = 0;
  MR[3] = 0;
  MG[3] = 255;
  MB[3] = 255;
  MR[4] = 255;
  MG[4] = 0;
  MB[4] = 0;
  MR[5] = 255;
  MG[5] = 0;
  MB[5] = 255;
  MR[6] = 255;
  MG[6] = 255;
  MB[6] = 0;
  MR[7] = 255;
  MG[7] = 255;
  MB[7] = 255;
}

int main(){

  make();

  char in[2];
  int status = 0;

  while(cin >> in[0]){
    if(in[0] == '0') break;

    int r, g, b;

    for(int i = 0; i < 3; i++){
      
      cin >> in[0] >> in[1];

      for(int j = 0; j <= 1; j++){
	if(in[j] == 'a') in[j] -= 39;
	if(in[j] == 'b') in[j] -= 39;
	if(in[j] == 'c') in[j] -= 39;
	if(in[j] == 'd') in[j] -= 39;
	if(in[j] == 'e') in[j] -= 39;
	if(in[j] == 'f') in[j] -= 39;
      }

      if(i == 0) r = (in[0] - 48) * 16 + (in[1] - 48);
      if(i == 1) g = (in[0] - 48) * 16 + (in[1] - 48);
      if(i == 2) b = (in[0] - 48) * 16 + (in[1] - 48);
    }

    long d;
    int min, then;

    for(int j = 0; j < 8; j++){
      d = sqrt((r - MR[j])*(r - MR[j])+(g - MG[j])*(g - MG[j])+(b - MB[j])*(b - MB[j]));
      if(j == 0 || min > d){
	min = d;
	then = j;
      }
    }

    if(then == 0) cout << "black" <<endl;
    if(then == 1) cout << "blue" <<endl;
    if(then == 2) cout << "lime" <<endl;
    if(then == 3) cout << "aqua" <<endl;
    if(then == 4) cout << "red" <<endl;
    if(then == 5) cout << "fuchsia" <<endl;
    if(then == 6) cout << "yellow" <<endl;
    if(then == 7) cout << "white" <<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;
    rep (i,3) 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 <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

string color[8] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
string strength[8] = {"000000", "0000ff", "00ff00", "00ffff", "ff0000", "ff00ff", "ffff00", "ffffff"};

int toi(string s){
    int ret = 0;
    rep(i, s.size()){
        string t = s.substr(i, 1);
        if('0' <= t[0] && t[0] <= '9') ret += stoi(t);
        else ret += t[0]-'a'+10;
        if(i != s.size()-1) ret *= 16;
    }
    return ret;
}

vector<int> rgb(string s){
    vi ret;
    rep(i, 3){
        string t = s.substr(i*2, 2);
        ret.pb(toi(t));
    }
    return ret;
}

int main(){
    string  s;
    while(cin >> s, s!="0"){
        s = s.substr(1);
        vi c = rgb(s);
        int m = inf;
        int ans = 0;
        rep(i, 8){
            vi d = rgb(strength[i]);
            int ret = sqrt(pow(c[0]-d[0], 2)+pow(c[1]-d[1], 2)+pow(c[2]-d[2], 2));
            if(m > ret){ans = i; m = ret;}
        }
        cout << color[ans] << endl;
    }
}

C++: #include<iostream>
#include<string>
using namespace std;
int main() {
	string a;
	string c[8] = { "black","blue","lime","aqua","red","fuchsia","yellow","white" };
	int d[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} };
	while (cin>>a&&a!="0")
	{
		int t[3];
		for (int i = 1; i < a.length(); i += 2) {
			int b = 0;
			for (int j = 0; j <= 1; j++) {
				if ((int)a[i + j] >= '0' && (int)a[i +j] <= '9')
					b += (pow(16, (j+1)%2)*(int)(a[i +j] - '0'));
				else 
					b += (pow(16, (j+1)%2)*(10 + (int)a[i + j] - 'a'));
			}
			t[(i - 1) / 2] = b;
		}
		double e = 100000;
		string f = "";
		for (int i = 7; i >= 0; i--) {
			double g = sqrt(pow((t[0] - d[i][0]), 2) + pow((t[1] - d[i][1]), 2) + pow((t[2] - d[i][2]), 2));
			if (g <= e) {
				e = g;
				f = c[i];
			}
		}
		cout << f << endl;
	}
}