Mine!
def check_count_in_range(password, letter, start, stop): return password.count(letter) >= start and password.count(letter) <= stop def check_indexes(password, letter, start, stop): return (password[start] == letter or password[stop] == letter) and (password[start] != password[stop]) with open('input.txt') as file: letters = [num.split(": ") for num in file] part1_tally = 0 part2_tally = 0 for policy, password in letters: length, letter = policy.split(" ") start, stop = length.split("-") start, stop = int(start), int(stop) # part 1 if check_count_in_range(password, letter, start, stop): part1_tally += 1 # part 2 if check_indexes(password, letter, start - 1, stop - 1): part2_tally += 1 print("Part 1", part1_tally) print("Part 2", part2_tally)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Mine!