COMPONENT_LENGTH = 3 def blend(c1: int, c2: int) -> int: """Get the median of 2 numbers.""" return round((c1 + c2) / 2) def splitColors(rgb: int) -> tuple[int, int, int]: """Split an RGB value into its components.""" (r, g, b) = [ int(str(rgb).zfill(3 * COMPONENT_LENGTH)[i : i + COMPONENT_LENGTH]) for i in range(0, 3 * COMPONENT_LENGTH, COMPONENT_LENGTH) ] return (r, g, b) def blendColors(rgb1: int, rgb2: int) -> int: """Blend two colors represented as RGB values.""" (r1, g1, b1) = splitColors(rgb1) (r2, g2, b2) = splitColors(rgb2) (r3, g3, b3) = [ blend(r1, r2), blend(g1, g2), blend(b1, b2), ] # Pad with leading zeros (final_r, final_g, final_b) = [str(x).zfill(COMPONENT_LENGTH) for x in (r3, g3, b3)] # Compose components and cast to integer return int(final_r + final_g + final_b) print("Testing blendColors()...", end="") assert blendColors(204153050, 104000152) == 154076101 assert blendColors(220153102, 151189051) == 186171076 assert blendColors(153051153, 51204) == 76051178 assert blendColors(123456789, 123456789) == 123456789 assert blendColors(0, 0) == 0 print("Passed!")