Can't quite pin this down
I've tried a few iterations, but can't quite get this. I've passed all of the self-checking tests, even the additional tests suggested by Gabbek in the other discussion post for this challenge. This will even pass the first big test (Big/1). but it fails on Big/2. (It says the correct answer is 8; my code finds 9.) Could someone help me figure out where the flaw in my logic is??
from math import ceil difficulties = lambda q: [ ceil((i[-1] - i[0]) / (len(i) - 1)) for i in q ] def workout(sessions, additional) -> int: # Transform from list [x, y, z, ...], turn to [(x,y), (y,z), ...] sessions = [[i, j] for i, j in zip(sessions[:-1], sessions[1:])] while additional > 0: # difficulties() [at top] will take index[-1] - index[0] of each list in sessions, # and will divide by len() - 1 to give us the difference in number of pushups # capable over those workouts, including with any additional workouts we've added. gaps = difficulties(sessions) # we want index of the highest difficulty gap, to add workouts to break it up. # Then change that difficulty to '0' in this so we can evaluate other difficulties. m = gaps.index( max(gaps) ) gaps[m] = 0 # This will break the difficulty in 2, if we only add 1 workout. # (Continues to divide by 3, or 4, etc., depending on how many workouts we'll add) breaks = 2 # While the broken-up difficulty is still higher than next max difficulty, # add another workout to break it up. while (sessions[m][-1] - sessions[m][0]) // breaks >= max(gaps) and breaks <= additional: breaks += 1 # When I know how many breaks to add, add that number of '+' for i in range(1, breaks): sessions[m].insert(i, '+') # Number of workouts to add is the # of breaks - 1 # (e.g., halving the difficulty means adding 1 workout) additional -= (breaks - 1) return max(difficulties(sessions))