rename stuff
This commit is contained in:
1 parent
7c3d439f6e
commit
97ddc36b62
325 files changed
+85
No files matched your search
@@ -0,0 +1,49 @@
|
||||
|
||||
import re
|
||||
|
||||
|
||||
# decode line into bounds and letter and password
|
||||
def decode_line(l):
|
||||
groups = re.compile(r"(?P<lower>\d+)-(?P<higher>\d+) (?P<letter>\w): (?P<pwd>\w+)").search(l)
|
||||
return groups
|
||||
|
||||
|
||||
# check if valid with certain number of chars
|
||||
def check_if_valid(lower, higher, letter, pwd):
|
||||
if int(lower) <= pwd.count(letter) <= int(higher):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
# check if valid with chars on places
|
||||
def check_if_valid2(lower, higher, letter, pwd):
|
||||
# both = line.split(": ")
|
||||
# cond = both[0].split(" ")
|
||||
# times = cond[0].split("-")
|
||||
# lower = int(times[0])
|
||||
# higher = int(times[1])
|
||||
# letter = cond[1]
|
||||
# pwd = (both[1])[:-1]
|
||||
if (pwd[int(lower) - 1] == letter) != (pwd[int(higher) - 1] == letter):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
with open(r"C:\Users\Maya\Desktop\Uni\WS_2021\AoC\input02") as f:
|
||||
lines = f.readlines()
|
||||
|
||||
# count for challenge 1
|
||||
i = 0
|
||||
for line in lines:
|
||||
if check_if_valid(*decode_line(line).groups()):
|
||||
i += 1
|
||||
print(i)
|
||||
|
||||
# count for challenge 2
|
||||
i = 0
|
||||
for line in lines:
|
||||
if check_if_valid2(*decode_line(line).groups()):
|
||||
i += 1
|
||||
print(i)
|
||||
Reference in new issue
Block a user