-
Notifications
You must be signed in to change notification settings - Fork 0
/
day2.py
29 lines (25 loc) · 875 Bytes
/
day2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from operator import xor
def split_number(numbers):
arrnum = numbers.split("-")
return arrnum
def poscontains(position, string, char):
if char == string[int(position)]:
return True
else:
return False
with open('input_day2.txt', newline='') as file:
lines = file.readlines()
validpassword = []
for line in lines:
split = line.split(":")
rules = split[0].split(" ")
numbers = rules[0]
letter = rules[1]
count = int(split[1].count(letter))
highlow = split_number(numbers)
#if (count <= int(highlow[1])) & (count >= int(highlow[0])):
# print(count)
# validpassword.append(split[1])
if xor(poscontains(highlow[0], split[1], letter), poscontains(highlow[1], split[1], letter)):
validpassword.append(split[1])
print(len(validpassword))