-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday2.py
40 lines (29 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
30
31
32
33
34
35
36
37
38
39
40
# -*- coding: utf-8 -*-
"""
Created on Wed Dec 2 15:43:14 2020
@author: rundx
"""
f = open('day2.txt', 'r')
lines = []
for line in f:
lines.append(line.rstrip())
passwordTuples = []
for password in lines:
new = password.split(' ')
counts = new[0].split('-')
passTuple = (int(counts[0]), int(counts[1]), new[1][0], new[2])
passwordTuples.append(passTuple)
valid = 0
for combo in passwordTuples:
if combo[-1].count(combo[-2]) <= combo[1] and combo[-1].count(combo[-2]) >= combo[0]:
valid+=1
print(valid)
valid2 = 0
for combo in passwordTuples:
if combo[1] > len(combo[-1]):
continue
if combo[-1][combo[0]-1] == combo[-2] or combo[-1][combo[1]-1] == combo[-2]:
valid2+=1
if combo[-1][combo[0]-1] == combo[-2] and combo[-1][combo[1]-1] == combo[-2]:
valid2-=1
print(valid2)