-
Notifications
You must be signed in to change notification settings - Fork 0
/
day4_part2.py
54 lines (38 loc) · 1.35 KB
/
day4_part2.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import itertools
import re
def checkDecrease(number):
result = all(x <= y for x, y in zip(list(number), list(number)[1:]))
return result
def checkDoubles(number):
result = any(x == y for x, y in zip(list(number), list(number)[1:]))
return result
def checkPartOfGroup(number):
doublesList = []
for x, y in zip(list(number), list(number)[1:]):
if x == y:
doublesList.append("{}{}".format(x,y))
checkList = []
for doubles in doublesList:
coordinates = [m.start() for m in re.finditer(doubles, number)]
for coords in coordinates:
if coords == 4:
if number[coords - 1] == number[coords] == number[coords + 1]:
checkList.append(True)
elif number[coords] == number[coords + 1]:
checkList.append(False)
elif number[coords] == number[coords + 2]:
checkList.append(True)
else:
checkList.append(False)
if False in checkList:
return False
else:
return True
totalList = []
for password in range(130254, 678275):
password = str(password)
if (checkDoubles (password) == True and
checkDecrease (password) == True and
checkPartOfGroup(password) == False):
totalList.append(password)
print(len(totalList))