diff --git a/python/sep30/level3/numberOfSteps.py b/python/sep30/level3/numberOfSteps.py index 9400213..fa032a3 100644 --- a/python/sep30/level3/numberOfSteps.py +++ b/python/sep30/level3/numberOfSteps.py @@ -6,7 +6,7 @@ def numberOfSteps(bricks: int) -> int: Given a number of bricks return how many steps would be required to use them all given that: S(0) = 0 S(n) = S(n-1) + n - Formula: `n=(-1+sqrt(1+8*bricks))/2` + Formula: `S=(-1+sqrt(1+8*n))/2` """ return ceil((-1 + sqrt(1 + 8 * bricks)) / 2) diff --git a/python/sep30/level4/blendColors.py b/python/sep30/level4/blendColors.py index 668027e..5e91ceb 100644 --- a/python/sep30/level4/blendColors.py +++ b/python/sep30/level4/blendColors.py @@ -1,10 +1,21 @@ +def blendComponent(c1: int, c2: int) -> int: + """Get the median of 2 numbers.""" + return round((c1 + c2) / 2) + + def blendColors(rgb1: int, rgb2: int) -> int: """Blend two colors represented as RGB values.""" + # Fill values and split into individual components (r1, g1, b1) = [int(str(rgb1).zfill(9)[i : i + 3]) for i in range(0, 9, 3)] (r2, g2, b2) = [int(str(rgb2).zfill(9)[i : i + 3]) for i in range(0, 9, 3)] # Calculate the average of each color component - (r3, g3, b3) = [round((r1 + r2) / 2), round((g1 + g2) / 2), round((b1 + b2) / 2)] + (r3, g3, b3) = [ + blendComponent(r1, r2), + blendComponent(g1, g2), + blendComponent(b1, b2), + ] (final_r, final_g, final_b) = [str(x).zfill(3) for x in (r3, g3, b3)] + # Compose components and cast to integer return int(final_r + final_g + final_b)