Here's my solution in Python
def partOne(low, high, letter, password): count = 0 for char in password: if char == letter: count += 1 return high >= count >= low def partTwo(position1, position2, letter, password): return (password[position1] == letter) ^ (password[position2] == letter) out1 = 0 out2 = 0 with open("Problem-2/Day-2-Password-Philosophy.txt") as file: for line in file: freq, letter, password = line.split(" ") letter = letter[:len(letter) - 1] low, high = map(int, freq.split('-')) if partOne(low, high, letter, password): out1 += 1 if partTwo(low - 1, high - 1, letter, password): out2 += 1 print(out1, out2)
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.
Here's my solution in Python