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)
	}
}

Python: colors = {
    'black': [0, 0, 0],
    'blue': [0, 0, 255],
    'lime': [0, 255, 0],
    'aqua': [0, 255, 255],
    'red': [255, 0, 0],
    'fuchsia': [255, 0, 255],
    'yellow':  [255, 255, 0],
    'white': [255, 255, 255]
}

while True:
    color = input()
    if color == '0':
        break
    r, g, b = (int(color[1:3], 16),
               int(color[3:5], 16),
               int(color[5:7], 16))
    print(r, g, b)
    near_color = ['', float('inf')]
    for k, v in colors.items():
        dk = ((v[0] - r) ** 2 +
              (v[1] - g) ** 2 +
              (v[2] - b) ** 2) ** .5
        if dk < near_color[1]:
            near_color = [k, dk]
    print(near_color[0])

Python: # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0176

"""
import sys
from sys import stdin
from collections import namedtuple
from math import sqrt
input = stdin.readline


color = namedtuple('color', ['name', 'r', 'g', 'b'])
def main(args):
    references = [color('black',   0x00, 0x00, 0x00), color('blue', 0x00, 0x00, 0xff), color('lime',    0x00, 0xff, 0x00),
                  color('aqua',    0x00, 0xff, 0xff), color('rea',  0xff, 0x00, 0x00), color('fuchsia', 0xff, 0x00, 0xff),
                  color('yellow', 0xff, 0xff, 0x00), color('white', 0xff, 0xff, 0xff)]

    while True:
        data = input().strip()
        if data[0] == '0':
            break
        my_r = int(data[1:3], 16)
        my_g = int(data[3:5], 16)
        my_b = int(data[5:7], 16)

        distances = []
        for c in references:
            d = sqrt((c.r - my_r)**2 + (c.g - my_g)**2 + (c.b - my_b)**2)
            distances.append(d)

        closest_distance = min(distances)
        closest_color = distances.index(closest_distance)
        print(references[closest_color].name)


if __name__ == '__main__':
    main(sys.argv[1:])

Python: while True:
    N = input()
    if N == "0":
        break

    r = int(N[1:3],16)
    g = int(N[3:5],16)
    b = int(N[5:7],16)

    ans = ""
    D = 255*255*3+1

    R, G, B = 0, 0, 0
    d = (R-r)**2 + (G-g)**2 + (B-b)**2
    if d < D:
        D = d
        ans = "black"

    R, G, B = 0, 0, 255
    d = (R - r) ** 2 + (G - g) ** 2 + (B - b) ** 2
    if d < D:
        D = d
        ans = "blue"

    R, G, B = 0, 255, 0
    d = (R - r) ** 2 + (G - g) ** 2 + (B - b) ** 2
    if d < D:
        D = d
        ans = "lime"

    R, G, B = 0, 255, 255
    d = (R - r) ** 2 + (G - g) ** 2 + (B - b) ** 2
    if d < D:
        D = d
        ans = "aqua"

    R, G, B = 255, 0, 0
    d = (R - r) ** 2 + (G - g) ** 2 + (B - b) ** 2
    if d < D:
        D = d
        ans = "red"

    R, G, B = 255, 0, 255
    d = (R - r) ** 2 + (G - g) ** 2 + (B - b) ** 2
    if d < D:
        D = d
        ans = "fuchsia"

    R, G, B = 255, 255, 0
    d = (R - r) ** 2 + (G - g) ** 2 + (B - b) ** 2
    if d < D:
        D = d
        ans = "yellow"

    R, G, B = 255, 255, 255
    d = (R - r) ** 2 + (G - g) ** 2 + (B - b) ** 2
    if d < D:
        D = d
        ans = "white"

    print(ans)

Python: import math


def translate(color):
    ret = 0
    cnt = 0
    for c in color:
        if c == "f":
            num = 15
        elif c == "e":
            num = 14
        elif c == "d":
            num = 13
        elif c == "c":
            num = 12
        elif c == "b":
            num = 11
        elif c == "a":
            num = 10
        else:
            num = int(c)

        if cnt == 0:
            ret += num * 16
            cnt += 1
        else:
            ret += num

    return ret


color = ["black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"]
stlength = [[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 1:
    n = input()
    if n == "0":
        break

    red = n[1:3]
    green = n[3:5]
    blue = n[5:7]

    red = translate(red)
    green = translate(green)
    blue = translate(blue)

    ans = 10**9
    for i, stl in enumerate(stlength):
        distance = math.sqrt(
            (stl[0]-red)**2 + (stl[1]-green)**2 + (stl[2]-blue)**2)
        if distance < ans:
            ans = distance
            name = color[i]

    print(name)

Python: import math
while True :
    color = [[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_16 = input()
    if color_16 == "0" :
        break
    
    color_R = int(color_16[1] + color_16[2], 16)
    color_G = int(color_16[3] + color_16[4], 16)
    color_B = int(color_16[5] + color_16[6], 16)
    
    min_d = 500
    for i in range(8) :
        R = color[i][0]
        G = color[i][1]
        B = color[i][2]
        d = math.sqrt((R - color_R)**2 + (G - color_G)**2 + (B - color_B)**2)
        if min_d > d :
            min_d = d
            color_num = i
    
    if color_num == 0 :
        print("black")
    elif color_num == 1 :
        print("blue") 
    elif color_num == 2 :
        print("lime")
    elif color_num == 3 :
        print("aqua")
    elif color_num == 4 :
        print("red")
    elif color_num == 5 :
        print("fuchsia")
    elif color_num == 6 :
        print("yellow")
    else :
        print("white")

Python: from collections import OrderedDict
colors = OrderedDict()
colors['black'] = [0, 0, 0]
colors['blue'] = [0, 0, 255]
colors['lime'] = [0, 255, 0]
colors['aqua'] = [0, 255, 255]
colors['red'] = [255, 0, 0]
colors['fuchsia'] = [255, 0, 255]
colors['yellow'] = [255, 255, 0]
colors['white'] = [255, 255, 255]

while True:
    color = input()
    if color == '0':
        break
    r, g, b = (int(color[1:3], 16),
               int(color[3:5], 16),
               int(color[5:7], 16))
    print(r, g, b)
    near_color = ['', float('inf')]
    for k, v in colors.items():
        print(k)
        dk = ((v[0] - r) ** 2 +
              (v[1] - g) ** 2 +
              (v[2] - b) ** 2) ** .5
        if dk < near_color[1]:
            near_color = [k, dk]
    print(near_color[0])

Python: # Aizu Problem 0176: What Color?
#
import sys, math, os, bisect

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")

colors = {"black": "#000000", "blue": "#0000ff", "lime": "#00ff00",
          "aqua": "#00ffff", "red": "#ff0000", "fuchsia": "#ff00ff",
          "yellow": "#ffff00", "white": "#ffffff"}

def distance(cc1, cc2):
    r1 = int(cc1[1:3], 16)
    r2 = int(cc2[1:3], 16)
    g1 = int(cc1[3:5], 16)
    g2 = int(cc2[3:5], 16)
    b1 = int(cc1[5:], 16)
    b2 = int(cc2[5:], 16)
    return math.sqrt((r1 - r2)**2 + (g1 - g2)**2 + (b1 - b2)**2)

    
def get_color(cc):
    min_dist = float('Inf')
    for color in colors:
        dist = distance(cc, colors[color])
        if dist < min_dist:
            min_dist = dist
            best = color
    return best


while True:
    cc = input().strip()
    if cc[0] == '0':
        break
    print(get_color(cc))