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: import math

sample1 = [ [0, 0, 0], [0, 0, 255], [0, 255, 0], [0, 255, 255], [255, 0, 0], [255, 0, 255], [255, 255, 0], [255, 255, 255] ]
sample2 = ['black', 'blue', 'lime', 'aqua', 'red', 'fuchsia', 'yellow', 'white']

while True:
    color = input()
    
    if color=='0':
        break
    
    Color = list(color)
    Color.pop(0)
    for i in range(6):
        if Color[i]=='a':
            Color.pop(i)
            Color.insert(i,10)
        if Color[i]=='b':
            Color.pop(i)
            Color.insert(i,11)
        if Color[i]=='c':
            Color.pop(i)
            Color.insert(i,12)
        if Color[i]=='d':
            Color.pop(i)
            Color.insert(i,13)
        if Color[i]=='e':
            Color.pop(i)
            Color.insert(i,14)
        if Color[i]=='f':
            Color.pop(i)
            Color.insert(i,15)
    
    R = int(Color[0])*16 + int(Color[1])
    G = int(Color[2])*16 + int(Color[3])
    B = int(Color[4])*16 + int(Color[5])
    
    D = []
    for i in range(8):
        d = math.sqrt( (R-sample1[i][0])**2 + (G-sample1[i][1])**2 + (B-sample1[i][2])**2 )
        D.append(d)
    dmin = min(D)
    index = D.index(dmin)
    print(sample2[index])

Python: L = [ [ 0, "black",     0,  0,    0 ],
      [ 1, "blue",      0,  0,  255 ],
      [ 2, "lime",      0, 255,   0 ],
      [ 3, "aqua",      0, 255, 255 ],
      [ 4, "red",     255,   0,   0 ],
      [ 5, "fuchsia", 255,   0, 255 ],
      [ 6, "yellow",  255, 255,   0 ],
      [ 7, "white",   255, 255, 255 ] ]

while True:
    T = []
    s = input()
    if s == "0":
        break
    code = []
    for i in range(3):
        code.append( int(s[1+2*i:3+2*i], 16) )
    for i in range(len(L)):
        m = 0
        for j in range(3):
            m += (L[i][2+j] - code[j])**2
        T.append( [ L[i][0], m] )
    T.sort(key=lambda x: (x[1], x[0]))
    print(L[T[0][0]][1])

Python: import math

while True :
    q = input()
    
    if(q == "0") :
        break
    
    else :
        Color = ["black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"]
        f = int("ff", 16)
        r = int(q[1] + q[2], 16)
        g = int(q[3] + q[4], 16)
        b = int(q[5] + q[6], 16)
        
        d1 = math.sqrt(r ** 2 + g ** 2 + b ** 2)
        d2 = math.sqrt(r ** 2 + g ** 2 + (b - f) ** 2)
        d3 = math.sqrt(r ** 2 + (g - f) ** 2 + b ** 2)
        d4 = math.sqrt(r ** 2 + (g - f) ** 2 + (b - f) ** 2)
        d5 = math.sqrt((r - f) ** 2 + g ** 2 + b ** 2)
        d6 = math.sqrt((r - f) ** 2 + g ** 2 + (b - f) ** 2)
        d7 = math.sqrt((r - f) ** 2 + (g - f) ** 2 + b ** 2)
        d8 = math.sqrt((r - f) ** 2 + (g - f) ** 2 + (b - f) ** 2)
        
        D = [d1, d2, d3, d4, d5, d6, d7, d8]
        
        d = min(D)
        print(Color[D.index(d)])

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('red',  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)
        distances = [((c.r - my_r)**2 + (c.g - my_g)**2 + (c.b - my_b)**2) for c in references]

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


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

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))
    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: # AOJ 0176: What Color?
# Python3 2018.6.19 bal4u

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

while True:
	a = list(input())
	if a[0] == '0': break
	r, g, b = int(a[1]+a[2], 16), int(a[3]+a[4], 16), int(a[5]+a[6], 16)
	vmin = 3* 0xff**2
	for i in color:
		d = (r-i[1])**2 + (g-i[2])**2 + (b-i[3])**2
		if d < vmin: j, vmin = i, d
	print(j[0])