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
}

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