-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadvent5.py
More file actions
52 lines (45 loc) · 1.01 KB
/
advent5.py
File metadata and controls
52 lines (45 loc) · 1.01 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
f = open('input5.txt', 'r')
strings = f.readlines()
f.close()
nice = 0
ix = 0
def isnice(s):
vowels = 0
previous = '0'
double = False
for x in s:
if x in ['a', 'e', 'i', 'o', 'u']:
vowels += 1
if x == previous:
double = True
if (previous, x) == ('a', 'b') or (previous, x) == ('c', 'd') or (previous, x) == ('p', 'q') or (previous, x) == ('x', 'y'):
return False
previous = x
print (double ,(vowels > 2))
if double and (vowels > 2):
return True
return False
def isnice_(s):
rule1 = False
rule2 = False
pairs = []
previous = '0'
prevpair = '00'
for x in s:
print previous + x
if previous + x in pairs[:-1]:
rule1 = True
if prevpair[0] == x:
rule2 = True
prevpair = previous + x
previous = x
pairs.append(prevpair)
print (rule1, rule2)
return rule1 and rule2
l = len(strings)
while not ix == l:
if isnice_(strings[ix]):
nice += 1
print nice
ix += 1
print nice