Skip to content

Instantly share code, notes, and snippets.

@scaffeinate
Last active February 4, 2019 07:19
Show Gist options
  • Save scaffeinate/f8586c9f94e94f9b2fe3474a1b414024 to your computer and use it in GitHub Desktop.
Save scaffeinate/f8586c9f94e94f9b2fe3474a1b414024 to your computer and use it in GitHub Desktop.
def findSchedules(workHours, dayHours, pattern):
totalHours = 0
result = []
for c in pattern:
if c != '?':
totalHours = totalHours + int(c)
diff = workHours - totalHours
constructResult(list(pattern), 0, diff, dayHours, result)
return result
def constructResult(patternArr, index, diff, dayHours, result):
if index == len(patternArr):
if diff == 0:
result.append(''.join(patternArr))
return
if patternArr[index] == '?':
for i in range(0, dayHours+1):
c = patternArr[index]
patternArr[index] = str(i)
constructResult(patternArr, index+1, diff-i, dayHours, result)
patternArr[index] = c
else:
constructResult(patternArr, index+1, diff, dayHours, result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment