first commit
This commit is contained in:
39
2020/02/02b.py
Executable file
39
2020/02/02b.py
Executable file
@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Advent Of Code 2020 - Day 2
|
||||
|
||||
"""
|
||||
1-5 k: kkkkhkkkkkkkkkk
|
||||
5-7 k: blkqhtxfgktdkxzkksk
|
||||
"""
|
||||
|
||||
filename = "input.txt"
|
||||
|
||||
def logical_xor(str1, str2):
|
||||
return bool(str1) ^ bool(str2)
|
||||
|
||||
with open(filename) as f:
|
||||
content = f.readlines()
|
||||
#content = [x.strip() for x in content]
|
||||
|
||||
validPasswords = 0
|
||||
|
||||
for i in content:
|
||||
line = i.split()
|
||||
|
||||
pos1 = int(line[0].split("-")[0])-1
|
||||
pos2 = int(line[0].split("-")[1])-1
|
||||
|
||||
character = line[1].rstrip(":")
|
||||
|
||||
password = line[2]
|
||||
p1 = password[pos1]
|
||||
p2 = password[pos2]
|
||||
|
||||
# (a and not b) or (not a and b)
|
||||
|
||||
if ( (p1 == character) and (p2 != character) ) or ( (p1 != character) and (p2 == character) ):
|
||||
validPasswords = validPasswords + 1
|
||||
|
||||
|
||||
print (validPasswords)
|
Reference in New Issue
Block a user