-
Notifications
You must be signed in to change notification settings - Fork 0
/
day4.py
36 lines (28 loc) · 856 Bytes
/
day4.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
def Solution1(input):
validCount = 0
with open(input, "r") as f:
for i, eachLine in enumerate(f):
if validPassPhrase1(eachLine):
validCount += 1
return validCount
def validPassPhrase1(line):
dictionary = set()
count = 0
for eachWord in line.strip().split(" "):
dictionary.add(eachWord)
count += 1
return count == len(dictionary)
def Solution2(input):
validCount = 0
with open(input, "r") as f:
for i, eachLine in enumerate(f):
if validPassPhrase2(eachLine):
validCount += 1
return validCount
def validPassPhrase2(line):
dictionary = set()
count = 0
for eachWord in line.strip().split(" "):
dictionary.add(''.join(sorted(set(eachWord.strip()))))
count += 1
return count == len(dictionary)