add answer 2
This commit is contained in:
parent
6722b2e52d
commit
458e998c3d
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,50 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
fd = open('input', 'r')
|
||||
lines = fd.readlines()
|
||||
|
||||
def checka(minimum, maximum, letter, string):
|
||||
cnt = 0
|
||||
for i in string:
|
||||
if i == letter: cnt += 1
|
||||
if cnt >= minimum and cnt <= maximum:
|
||||
return True
|
||||
return False
|
||||
|
||||
def checkb(minimum, maximum, letter, string):
|
||||
cnt = 0
|
||||
if string[minimum - 1] == letter: cnt += 1
|
||||
if string[maximum - 1] == letter: cnt += 1
|
||||
if cnt == 1: return True
|
||||
return False
|
||||
|
||||
def parse(line):
|
||||
colon = line.split(':')
|
||||
space = colon[0].split(' ')
|
||||
dash = space[0].split('-')
|
||||
|
||||
minimum = int(dash[0])
|
||||
maximum = int(dash[1])
|
||||
letter = space[1]
|
||||
string = colon[1].lstrip().rstrip()
|
||||
|
||||
return (minimum, maximum, letter, string)
|
||||
|
||||
def solutiona():
|
||||
cnt = 0
|
||||
for i in lines:
|
||||
parsed = parse(i)
|
||||
if checka(parsed[0], parsed[1], parsed[2], parsed[3]): cnt += 1
|
||||
|
||||
print(str(cnt))
|
||||
|
||||
def solutionb():
|
||||
cnt = 0
|
||||
for i in lines:
|
||||
parsed = parse(i)
|
||||
if checkb(parsed[0], parsed[1], parsed[2], parsed[3]): cnt += 1
|
||||
|
||||
print(str(cnt))
|
||||
|
||||
solutiona()
|
||||
solutionb()
|
Loading…
Reference in New Issue