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
}

C++: 
import java.awt.geom.Point2D;
import java.io.*;
import java.math.BigInteger;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Stack;
import java.util.TreeMap;



public class Main {

	static PrintWriter out = new PrintWriter(System.out);
	static FastScanner sc = new FastScanner();
	static Scanner stdIn = new Scanner(System.in);
	static int INF = 2 << 26;
	static int[][] X = new int[][] {{0,0,0},{0,0,255},{0,255,0},{0,255,255},{255,0,0},{255,0,255},{255,255,0},{255,255,255}};
	static String[] K = new String[] {"black","blue","lime","aqua","red","fuchsia","yellow","white"};
	public static void main(String[] args) {
		while(true) {
			String tmp = sc.next();
			if(tmp.equals("0")) break;
			int a1 = Integer.parseInt(tmp.substring(1, 3),16);
			int a2 = Integer.parseInt(tmp.substring(3, 5),16);
			int a3 = Integer.parseInt(tmp.substring(5, 7),16);
			double dkMax = Double.MAX_VALUE;
			int id = 0;
			for(int i = 0; i < X.length; i++) {
				double x = Math.sqrt(Math.pow((a1 - X[i][0]),2) + Math.pow((a2 - X[i][1]),2) +Math.pow((a3 - X[i][2]),2));
				if(dkMax > x) {
					dkMax = x;
					id = i;
				}
			}
			out.println(K[id]);
			
		}
		out.flush();
	}

}

//------------------------------//
//-----------//
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    
    public int nextInt() {
    	 if (!hasNext()) throw new NoSuchElementException();
         int n = 0;
         boolean minus = false;
         int b = readByte();
         if (b == '-') {
             minus = true;
             b = readByte();
         }
         if (b < '0' || '9' < b) {
             throw new NumberFormatException();
         }
         while(true){
             if ('0' <= b && b <= '9') {
                 n *= 10;
                 n += b - '0';
             }else if(b == -1 || !isPrintableChar(b)){
                 return minus ? -n : n;
             }else{
                 throw new NumberFormatException();
             }
             b = readByte();
         }
    }
    
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
    

}

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

char l[6];
string s;

string color() {
	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];

	//ff == 255;
	if (r <= 128) {
		//black,blue,lime,aqua
		if (g <= 128) {
			//black,blue
			if (b <= 128) {
				return "black";
			}
			else {
				return "blue";
			}
		}
		else {
			//lime,aqua
			if (b <= 128) {
				return "lime";
			}
			else {
				return "aqua";
			}
		}
	}
	else {
		//red,fuchsia,yellow,white
		if (g <= 128) {
			//red,fu
			if (b <= 128) {
				return "red";
			}
			else {
				return "fuchsia";
			}
		}
		else {
			if (b <= 128) {
				return "yellow";
			}
			else
			{
				return "white";
			}
		}
	}
}

int main() {
	string g[100];
	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;
}