-
Notifications
You must be signed in to change notification settings - Fork 0
/
05.py
67 lines (50 loc) · 1.12 KB
/
05.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
55
56
57
58
59
60
61
62
63
64
65
66
67
data = open('05.input').readlines()
# Part 1
count = 0
bad_chars = [ 'ab', 'cd', 'pq', 'xy' ]
vowels = 'aeiou'
for line in data:
# No bad chars
bad = [1 for b in bad_chars if b in line]
if len(bad) > 0:
continue
# Twice in a row
twice = False
for idx, c in enumerate(line):
if idx > 0 and line[idx-1] == c:
twice = True
if not twice:
continue
# Vowels
v = 0
v = sum([1 for c in line if c in vowels])
if v < 3:
continue
count += 1
print("Part 1: %d" % count)
# Part 2
count = 0
bad_chars = [ 'ab', 'cd', 'pq', 'xy' ]
vowels = 'aeiou'
for line in data:
# Repeat
repeat = False
for idx, c in enumerate(line):
if idx > 1 and line[idx-2] == c:
repeat = True
if not repeat:
continue
# Pair
pair = False
for idx, c in enumerate(line):
p = line[idx-1] + c
if idx > 1 and (
p in line[:idx-1]
or
p in line[idx+1:]
):
pair = True
if not pair:
continue
count += 1
print("Part 2: %d" % count)