-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay2.py
More file actions
55 lines (39 loc) · 945 Bytes
/
Day2.py
File metadata and controls
55 lines (39 loc) · 945 Bytes
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import re
file = open('input.txt')
input = file.readlines()
def eff(line):
parts = re.split('-| |: ', line.strip())
milo = int(parts[0])
maxx = int(parts[1])
key = parts[2]
passcode = parts[3]
moxie = passcode.count(key)
if milo <= moxie <= maxx:
return 'true'
else:
return 'false'
bob = 0
for each in input:
# print(eff(each))
if eff(each) == 'true':
bob = bob + 1
print(bob)
# Part 2
def esf(line):
parts = re.split('-| |: ', line.strip())
milo = int(parts[0])
maxx = int(parts[1])
key = parts[2]
passcode = parts[3]
position1 = passcode[milo-1]
position2 = passcode[maxx-1]
if (position1 == key and position2 != key) or (position2 == key and position1 != key):
return 'true'
else:
return 'false'
bill = 0
for each in input:
# print(eff(each))
if esf(each) == 'true':
bill = bill + 1
print(bill)