-
Notifications
You must be signed in to change notification settings - Fork 2
/
sol.py
29 lines (25 loc) · 794 Bytes
/
sol.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
import re
matcher= re.compile(r'(.)\1*')
def is_good_one(n):
sn = str(n)
return (
len(sn) == 6 and
any([sn[i]==sn[i-1] for i in range(1, len(sn))]) and
all([sn[i]>=sn[i-1] for i in range(1,len(sn))])
)
def is_good_two(n):
sn = str(n)
matches = [match.group() for match in matcher.finditer(sn)]
return (
len(sn) == 6 and
any([sn[i]==sn[i-1] for i in range(1, len(sn))]) and
all([sn[i]>=sn[i-1] for i in range(1,len(sn))]) and
any([len(x)==2 for x in matches])
)
def part_one(a, b):
return sum([is_good_one(n) for n in range(a,b+1)])
def part_two(a, b):
return sum([is_good_two(n) for n in range(a,b+1)])
inp = 206938,679128
print(f"Part one: {part_one(*inp)}")
print(f"Part two: {part_two(*inp)}")