From d21789ac861a72ad5d88bd01b541fc3fe6713951 Mon Sep 17 00:00:00 2001 From: Anson Date: Tue, 8 Dec 2020 20:35:02 -0700 Subject: [PATCH] star 4 --- day2/day2.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/day2/day2.py b/day2/day2.py index ae53870..494b46e 100644 --- a/day2/day2.py +++ b/day2/day2.py @@ -1,16 +1,15 @@ -input = open('day2\input.txt','r').readlines() +input = open("day2\input.txt", "r").readlines() # print(len(input)) valid = 0 for i in input: - a = int(i.split('-')[0]) - b = int(i.split(' ')[0].split('-')[1]) - key = i.split(' ')[1][0] - password = i.split(' ')[-1] + a = int(i.split("-")[0]) - 1 + b = int(i.split(" ")[0].split("-")[1]) - 1 + key = i.split(" ")[1][0] + password = i.split(" ")[-1] - if password.count(key) >= a and password.count(key) <= b: - valid = valid+1 - print(i) - - - print(valid) \ No newline at end of file + if (password[a] == key or password[b] == key) and (password[a] != password[b]): + valid = valid + 1 + + +print(valid)