# Do names have colors?

*Now they do.*

Make a function that takes in a name (Any string two chars or longer really, but the name is the idea) and use the ascii values of it's substrings to produce the hex value of its color! Here is how it's going to work:

* The first two hexadecimal digits are the *SUM* of the value of characters (modulo 256).
* The second two are the *PRODUCT* of all the characters (again, modulo 256, which is one more than `FF` in hexadecimal).
* The last two are the *ABSOLUTE VALUE of the DIFFERENCE* between the first letter, and the sum of every other letter. (I think you get the idea with the modulo thing).

For example `"Jack"` returns `"79CAE5"`, which is... **baby blue!**
```
"Jack"  #  "J" = 74, "a" = 97, "c" = 99, "k" = 107

74 + 97 + 99 + 107 = 377                   -->  mod 256 = 121  -->  hex: 79
74 * 97 * 99 * 107 = 76036554              -->  mod 256 = 202  -->  hex: CA
74 - (97 + 99 + 107) = -229  --> abs: 229  -->  mod 256 = 229  -->  hex: E5
```

NOTE: The function should return `None/nil` when the input is less than two chars.

Source: codewars | Difficulty: EASY
Tags: String algorithms

Ad-hoc

Starter code: def string_color(name):
	

Solutions:
from operator import sub, mul
from functools import reduce

def string_color(string):
	if len(string) < 2:
		return None
	r = sum(map(ord, list(string))) % 256
	g = reduce(mul, list(map(ord, list(string)))) % 256
	b = abs(reduce(sub, list(map(ord, list(string))))) % 256
	return '{:02X}{:02X}{:02X}'.format(r, g, b)


from functools import reduce
from operator import mul

def string_color(name):
	if len(name) > 1:
		xs = list(map(ord, name))
		r = sum(xs) % 256
		g = reduce(mul, xs) % 256
		b = abs(xs[0] - sum(xs[1:])) % 256
		return f'{r:02X}{g:02X}{b:02X}'


def string_color(name):
	if len(name) < 2:
		return None
	else:
		first = hex(sum((ord(char) for char in name)) % 256)[-2:]
		second = 1
		for char in name:
			second = second * ord(char)
		second = hex(second % 256)[-2:]
		third = ord(name[0]) - sum((ord(char) for char in name[1:]))
		third = hex(abs(third) % 256)[-2:]
		return (first + second + third).upper().replace('X', '0')


from operator import mul
from functools import reduce

def string_color(s):
	if len(s) > 1:
		a = [ord(x) for x in s]
		n = sum(a)
		return f'{n % 256:02X}{reduce(mul, a) % 256:02X}{abs(a[0] * 2 - n) % 256:02X}'


def string_color(name):
	first_char = length = other_chars = sum_chars = 0
	prod_chars = 1
	for (i, a) in enumerate(name):
		current = ord(a)
		length += 1
		if i == 0:
			first_char = current
		else:
			other_chars += current
		prod_chars *= current
		sum_chars += current
	if length < 2:
		return None
	return '{:02X}{:02X}{:02X}'.format(sum_chars % 256, prod_chars % 256, abs(first_char - other_chars) % 256)


import operator as op
from functools import reduce

def string_color(name):
	if name == '':
		return None
	lst = [ord(i) for i in name]
	a = sum(lst) % 256
	b = reduce(op.mul, lst) % 256
	c = abs(lst[0] - sum(lst[1:])) % 256
	(a, b, c) = (format(a, 'x').upper().zfill(2), format(b, 'x').upper().zfill(2), format(c, 'x').upper().zfill(2))
	return a + b + c if not a == b == c else None


def string_color(name):
	if len(name) < 2:
		return None
	ascii = [ord(el) for el in name]
	s1 = hex(sum(ascii) % 256)[2:].upper()
	s2 = 1
	for el in ascii:
		s2 *= el
	s2 = hex(s2 % 256)[2:].upper()
	s3 = hex(abs(ascii[0] - sum(ascii[1:])) % 256)[2:].upper()
	lst = [s1, s2, s3]
	lst = ['0' + el if len(el) < 2 else el for el in lst]
	return ''.join(lst)