-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaoc4.py
More file actions
40 lines (24 loc) · 823 Bytes
/
aoc4.py
File metadata and controls
40 lines (24 loc) · 823 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
from collections import Counter
from itertools import tee
bottom, top = (int(i) for i in open('input.txt', 'r').readline().split('-'))
numbers = (str(n) for n in range(bottom, top + 1))
def partOneCriteria(num):
isPair = False
for a, b in pairwise(num):
if a > b:
return False
if a == b:
isPair = True
return isPair
def pairwise(iterable):
"s -> (s0,s1), (s1,s2), (s2, s3), ..."
a, b = tee(iterable)
next(b, None)
return zip(a, b)
def partTwoCriteria(num):
return 2 in Counter(num).values()
viableNums = [num for num in numbers if partOneCriteria(num)]
partOneCriteriaAmount = len(viableNums)
print("1:", partOneCriteriaAmount)
partTwoCriteriaAmount = sum(partTwoCriteria(num) for num in viableNums)
print("2:", partTwoCriteriaAmount)