Problem:


何色？

ウェブデザイナーを目指す太郎君はただいま修行中。事務所の先輩から「このページの背景色は#ffe085で」と、ウェブデザイン特有の色番号で指示されるのですが、それがどんな色かパッと思い浮かべることができません。

この色番号は光の三原色である赤、緑、青それぞれの強さを表わしています。具体的には2 桁の 16 進数を3 つ組み合わせたもので、色番号を“#RGB”とするとき、R は赤の強さ、G は緑の強さ、は青の強さを表します。それぞれ 00 から ff までの値になります。

色番号にまだ不慣れな太郎君のために、色番号を入力とし、色の表の中からもっとも近い色の名前
を出力するプログラムを作成してください。使用する色の表は以下の通りです。

  色の名前赤の強さ 緑の強さ 青の強さ

black 00 00   00

blue  00 00   ff

    lime  00 ff   00

    aqua  00 ff   ff

     red  ff 00   00

  fuchsia ff 00   ff

   yellow ff ff   00

    white ff ff   ff

「もっとも近い色」とは、以下のように定義します。与えられた色番号での赤、緑、青の強さをそれぞれ R、G、B とし、表の k 番目の色の赤、緑、青の強さをそれぞれ Rk、Gk、Bk とするとき、次の式で計算する dk の値が最も小さい色がもっとも近い色とします。

なお、dk の値が同じになる色が複数存在する場合は表の中でより上にある色がもっとも近い色になり
ます。

Input

複数のデータセットの並びが入力として与えられます。入力の終わりはゼロひとつの行で示されます。各データセットとして、色番号を表す文字列が、#RGB 形式で１行に与えられます。

データセットの数は 1000 を超えません。

Output

データセット毎に最も近い色の名前を１行に出力します。

Sample Input

#ffe085
#787878
#decade
#ff55ff
0

Output for the Sample Input

white
black
white
fuchsia



Sample input:
#ffe085
#787878
#decade
#ff55ff
0


Sample output:
white
black
white
fuchsia

Submission status: Wrong Answer

Solution code:
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))

Submission status: Wrong Answer

Solution code:
# -*- 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:])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
clr=["black","blue","lime","aqua","red","fuchsha","yellow","white"]
hex=["000000","0000ff","00ff00","00ffff","ff0000","ff00ff","ffff00","ffffff"]
def L(s1,s2):
	return ((int(s1[:2],16)-int(s2[:2],16))**2+(int(s1[2:4],16)-int(s2[2:4],16))**2+(int(s1[4:],16)-int(s2[4:],16))**2)**0.5

def nn(s):
	mn=mni=999
	for i in range(8):
		if mn>L(hex[i],s):
			mn=L(hex[i],s);mni=i
	return mni

while 1:
	rgb=raw_input()
	if rgb=="0":break
	print clr[nn(rgb[1:])]

Submission status: Wrong Answer

Solution code:
clr=["black","blue","lime","aqua","red","fuchsha","yellow","white"]
hex=["000000","0000ff","00ff00","00ffff","ff0000","ff00ff","ffff00","ffffff"]
def L(s1,s2):
	return ((int(s1[:2],16)-int(s2[:2],16))**2+(int(s1[2:4],16)-int(s2[2:4],16))**2+(int(s1[4:],16)-int(s2[4:],16))**2)**0.5

def nn(s):
	mn=mni=99999
	for i in range(8):
		if mn>L(hex[i],s):
			mn=L(hex[i],s);mni=i
	return mni

while 1:
	rgb=raw_input()
	if rgb=="0":break
	print clr[nn(rgb[1:])]

Submission status: Accepted

Solution code:
import math

def proc(s):
    r=int(s[0:2],16)
    g=int(s[2:4],16)
    b=int(s[4:6],16)
    return (r,g,b)

def dist(a,b):
    sum=0
    for i in xrange(3):
        sum+=(a[i]-b[i])**2
    return math.sqrt(sum)

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


while True:
    try:
        s=raw_input()[1:]
        if s=="": break
        mind=255*255*255
        for i in colors:
            if dist(proc(s),proc(colors[i]))<mind:
                mind=dist(proc(s),proc(colors[i]))
                color=i
        print color
    except EOFError: break

Submission status: Accepted

Solution code:
C = 'black blue lime aqua red fuchsia yellow white'.split()
while 1:
  a = raw_input()
  if a=="0": break
  print C[int("".join(['01'[int(a[i],16)>7] for i in [1,3,5]]),2)]

Submission status: Accepted

Solution code:
import math

def f(n):
    t = 0
    for i, c in enumerate(n):
        if c.isdigit():
            t += int(c)*(16**(1-i))
        else:
            if c == 'a':
                t += (16**(1-i))*10
            elif c == 'b':
                t += (16**(1-i))*11
            elif c == 'c':
                t += (16**(1-i))*12
            elif c == 'd':
                t += (16**(1-i))*13
            elif c == 'e':
                t += (16**(1-i))*14
            elif c == 'f':
                t += (16**(1-i))*15
    return t

def aaa():
    color = None
    s = None
    for k, v in data.items():
        t = 0
        for i in range(3):
            t += (RGB[i]-v[i])**2
        else:
            dk = math.sqrt(t)
        if s is None or dk < s:
            color = k
            s = dk
    else:
        print color

data = {'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:
    line = raw_input()
    if line == '0': break
    color = line[1:]
    RGB = [f(color[i:i+2]) for i in range(0, 6, 2)]
    aaa()

Submission status: Accepted

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

def list_chunk(arr, n):
	return [arr[i:i+3] for i in range(0,15,n)]

def code2rgb(code):
	code = code.lstrip('#')
	r, g, b = [code[i:i+2] for i in range(0,len(code),2)]
	return [int(v, 16) for v in [r, g, b]]
def dk2(a, b):
	return sum([(a[i]-b[i])**2 for i in range(0,3)])


while True:
	v = input()
	if(v is '0'): break
	rgb = code2rgb(v)
	dks = [dk2(code2rgb(c), rgb) for c in color.values()]
	k = list(color.keys())
	print(k[dks.index(min(dks))])

Submission status: Accepted

Solution code:
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 = "yellow"
	
	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))

Submission status: Accepted

Solution code:
# 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))

Submission status: Accepted

Solution code:
# -*- 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)

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


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

Submission status: Accepted

Solution code:
# -*- 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:])

Submission status: Accepted

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

Submission status: Accepted

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

while True:

    input_data = input()

    if len(input_data) == 1:
        break

    color_code = ""

    for first, second in zip(input_data[1::2], input_data[2::2]):
        if int(first + second, 16) <= 127:
            color_code += "00"
        else:
            color_code += "ff"

    print(COLOR[color_code])

Submission status: Accepted

Solution code:
# 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])

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
import math
L=[
("black",00,00,00),
("blue",00,00,255),
("lime",00,255,00),
("aqua",00,255,255),
("red",255,00,00),
("fuchsia",255,00,255),
("yellow",255,255,00),
("white",255,255,255)]
while True:
    c=raw_input()
    if c=="0":break
    Rk,Gk,Bk=int(c[1:3],16),int(c[3:5],16),int(c[5:7],16)
    m=10000
    for cl,r,g,b in L:
        t=math.sqrt(pow(r-Rk,2)+pow(g-Gk,2)+pow(b-Bk,2))
        if t<m:
            m=t
            color=cl
    print color

Submission status: Accepted

Solution code:
from operator import add
color = {"black":"000000","blue":"0000ff",
         "lime":"00ff00","aqua":"00ffff",
         "red":"ff0000","fuchsia":"ff00ff",
         "yellow":"ffff00","white":"ffffff"}

def parse(s):
    return map(lambda x:int(x,16), map(add,s[::2],s[1::2]))

def d(s1, s2,k):
    return sum(map(lambda a,b:(a-b)**2, *map(parse,(s1,s2))))

while True:
    s = raw_input()
    if s == "0":
        break
    print min(color.items(), key = lambda (k,v):d(s[1:],v,k))[0]

Submission status: Accepted

Solution code:
dc = {
    "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 1:
    s = raw_input()
    if s=="0": break
    g = [int(s[2*i+1:2*i+3],16) for i in xrange(3)]
    m = 1000000; ans = "";
    for k,v in dc.items():
        d = sum((v[i]-g[i])**2 for i in xrange(3))
        if d<m:
            m = d; ans = k;
    print ans

Submission status: Accepted

Solution code:
clr=["black","blue","lime","aqua","red","fuchsia","yellow","white"]
hex=["000000","0000ff","00ff00","00ffff","ff0000","ff00ff","ffff00","ffffff"]
def L(s1,s2):
	return ((int(s1[:2],16)-int(s2[:2],16))**2+(int(s1[2:4],16)-int(s2[2:4],16))**2+(int(s1[4:],16)-int(s2[4:],16))**2)**0.5

def nn(s):
	mn=mni=99999
	for i in range(8):
		if mn>L(hex[i],s):
			mn=L(hex[i],s);mni=i
	return mni

while 1:
	rgb=raw_input()
	if rgb=="0":break
	print clr[nn(rgb[1:])]

Submission status: Accepted

Solution code:
ff=255
clr=["black","blue","lime","aqua","red","fuchsia","yellow","white"]
val=[[0,0,0],[0,0,ff],[0,ff,0],[0,ff,ff],[ff,0,0],[ff,0,ff],[ff,ff,0],[ff,ff,ff]]

def L(s1,s2):
	return ((s1[0]-s2[0])**2+(s1[1]-s2[1])**2+(s1[2]-s2[2])**2)**0.5
	
while 1:
	rgb=raw_input()
	if rgb=="0":break
	rgb=[int(rgb[1:3],16),int(rgb[3:5],16),int(rgb[5:],16)]
	print clr[min([[L(rgb,val[i]),i] for i in range(8)])[1]]

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 参考:http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2797666#1

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

while True:
    s = input()
    if len(s) == 1:
        break
    color = ""

    for first, second in zip(s[1::2], s[2::2]):
        if int(first + second, 16) <= 127:
            color += "00"
        else:
            color += "ff"
    print(COLOR[color])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
color = {
    "000000": "black",
    "0000ff": "blue",
    "00ff00": "lime",
    "00ffff": "aqua",
    "ff0000": "red",
    "ff00ff": "fuchsia",
    "ffff00": "yellow",
    "ffffff": "white"
}
 
while True:
    n = input()
    if n == '0': break
    code = ''
    for f, s in zip(n[1::2], n[2::2]):
        if int(f+s, 16) <= 127:
            code += '00'
        else:
            code += 'ff'
    print(color[code])

Submission status: Accepted

Solution code:
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)