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

Python: colors = {}
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():
        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: INF = 10 ** 10
dic = {}
for i in range(10):
  dic[str(i)] = i
for i in range(ord("a"), ord("f") + 1):
  dic[chr(i)] = i - ord("a") + 10

def hex_to_dec(s):
  return dic[s[0]] * 16 + dic[s[1]]

colors = [("black",   list(map(hex_to_dec, ["00", "00", "00"]))),
          ("blue",    list(map(hex_to_dec, ["00", "00", "ff"]))),
          ("lime",    list(map(hex_to_dec, ["00", "ff", "00"]))),
          ("aqua",    list(map(hex_to_dec, ["00", "ff", "ff"]))),
          ("red",     list(map(hex_to_dec, ["ff", "00", "00"]))),
          ("fuchsia", list(map(hex_to_dec, ["ff", "00", "ff"]))),
          ("yellow",  list(map(hex_to_dec, ["ff", "ff", "00"]))),
          ("white",   list(map(hex_to_dec, ["ff", "ff", "ff"])))]

while True:
  s = input()
  if s == "0":
    break
  r, g, b = map(hex_to_dec, [s[1:3], s[3:5], s[5:7]])
  lowest_name = "KUWA"
  lowest_score = INF
  for name, rgb in colors:
    rc, gc, bc = rgb
    score = (r - rc) ** 2 + (g - gc) ** 2 + (b - bc) ** 2
    if score < lowest_score:
      lowest_name, lowest_score = name, score
  print(lowest_name)

Python: import math

def solve(line):
	R = int(line[1:3], 16)
	G = int(line[3:5], 16)
	B = int(line[5:7], 16)
	
	sa_black = math.sqrt(R**2 + G**2 + B**2)
	sa_max = sa_black
	ans_color = "black"
	
	sa_blue = math.sqrt(R**2 + G**2 + (B - 255)**2)
	if sa_blue < sa_max:
		sa_max = sa_blue
		ans_color = "blue"
	
	sa_lime = math.sqrt(R**2 + (G - 255)**2 + B**2)
	if sa_lime < sa_max:
		sa_max = sa_lime
		ans_color = "lime"
	
	sa_aqua = math.sqrt(R**2 + (G - 255)**2 + (B - 255)**2)
	if sa_aqua < sa_max:
		sa_max = sa_aqua
		ans_color = "aqua"
	
	sa_red = math.sqrt((R - 255)**2 + G**2 + B**2)
	if sa_red < sa_max:
		sa_max = sa_red
		ans_color = "red"
	
	sa_fuchsia = math.sqrt((R - 255)**2 + G**2 + (B - 255)**2)
	if sa_fuchsia < sa_max:
		sa_max = sa_fuchsia
		ans_color = "fuchsia"
	
	sa_yellow = math.sqrt((R - 255)**2 + (G - 255)**2 + B**2)
	if sa_yellow < sa_max:
		sa_max = sa_yellow
		ans_color = "blue"
	
	sa_white = math.sqrt((R - 255)**2 + (G - 255)**2 + (B - 255)**2)
	if sa_white < sa_max:
		sa_max = sa_white
		ans_color = "white"

	return ans_color

while True:
	line = input()
	if line == '0': break
	print(solve(line))