-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday2.py
More file actions
38 lines (32 loc) · 1.03 KB
/
day2.py
File metadata and controls
38 lines (32 loc) · 1.03 KB
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
from aocd.models import Puzzle
def solve_puzzle_one(input_array):
count = 0
for line in input_array:
partition = line.rpartition(':')
pattern = partition[0].rpartition(' ')
range = pattern[0]
char = pattern[2]
start = int(range.split('-')[0])
end = int(range.split('-')[1])
nums = partition[2].count(char)
if start <= nums <= end:
count += 1
print(count)
def solve_puzzle_two(input_array):
count = 0
for line in input_array:
partition = line.rpartition(':')
pattern = partition[0].rpartition(' ')
range = pattern[0]
char = pattern[2]
first = int(range.split('-')[0])
second = int(range.split('-')[1])
if sum([partition[2][first] == char, partition[2][second] == char]) == 1:
count += 1
print(count)
if __name__ == '__main__':
puzzle = Puzzle(year=2020, day=2)
array = puzzle.input_data.splitlines()
print(array)
solve_puzzle_one(array)
solve_puzzle_two(array)