Noëlle 3 anos atrás
pai
commit
c413465f43
1 arquivos alterados com 23 adições e 0 exclusões
  1. 23
    0
      day2a.py

+ 23
- 0
day2a.py Ver arquivo

@@ -0,0 +1,23 @@
import re

def checkpw(a, b, l, pw):
print(a, b, l, pw)
c = pw.count(l)
if a <= c <= b:
return True
return False

def main():
patt = re.compile("^(\d+)-(\d+) (.): (.+)$")
with open("input2.txt") as file:
lines = file.readlines()
ln = []
for line in lines:
m = re.match(patt, line)
ln.append([int(m.group(1)), int(m.group(2)), m.group(3), m.group(4)])
valid = [pw for pw in ln if checkpw(pw[0], pw[1], pw[2], pw[3])]
print(f"There are {len(valid)} valid passwords out of {len(ln)}.")


if __name__ == "__main__":
main()

Carregando…
Cancelar
Salvar