CMU Coding Bootcamp

feat: more code cleanup

thecoded.prof 0e19555c 49969d7c

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