day 2
This commit is contained in:
parent
3b529916d2
commit
5fa98c8f55
1 changed files with 33 additions and 0 deletions
33
02/02.py
Normal file
33
02/02.py
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
ints = []
|
||||||
|
for line in sys.stdin:
|
||||||
|
instructions = line.rstrip().split(' ')
|
||||||
|
|
||||||
|
c = instructions[0].split('-')
|
||||||
|
c_min = int(c[0])
|
||||||
|
c_max = int(c[1])
|
||||||
|
c_char = instructions[1][0]
|
||||||
|
pw = instructions[2]
|
||||||
|
|
||||||
|
# Part 1 test
|
||||||
|
count = 0
|
||||||
|
for c in pw:
|
||||||
|
if c == c_char:
|
||||||
|
count = count + 1
|
||||||
|
|
||||||
|
if c_min <= count <= c_max:
|
||||||
|
print(1, pw)
|
||||||
|
|
||||||
|
# Part 2 test
|
||||||
|
count2 = 0
|
||||||
|
if c_min <= len(pw) and pw[c_min - 1] == c_char:
|
||||||
|
count2 = count2 + 1
|
||||||
|
|
||||||
|
if c_max <= len(pw) and pw[c_max - 1] == c_char:
|
||||||
|
count2 = count2 + 1
|
||||||
|
|
||||||
|
if count2 == 1:
|
||||||
|
print(2, pw)
|
Loading…
Add table
Add a link
Reference in a new issue