Last active
February 4, 2019 07:19
-
-
Save scaffeinate/f8586c9f94e94f9b2fe3474a1b414024 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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