Started with 2020 because I need stars for Beeminder
This commit is contained in:
34
2020/d2.py
Normal file
34
2020/d2.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from lib import get_data
|
||||
|
||||
|
||||
def part_1(data):
|
||||
r = 0
|
||||
for line in data.splitlines():
|
||||
pol, pas = line.split(": ")
|
||||
nums, letter = pol.split(" ")
|
||||
lo, hi = list(map(int, nums.split("-")))
|
||||
c = pas.count(letter)
|
||||
if c >= lo and c <= hi:
|
||||
r += 1
|
||||
print(r)
|
||||
|
||||
r = 0
|
||||
for line in data.splitlines():
|
||||
pol, pas = line.split(": ")
|
||||
nums, letter = pol.split(" ")
|
||||
lo, hi = list(map(int, nums.split("-")))
|
||||
c = pas.count(letter)
|
||||
if (pas[lo - 1] == letter or pas[hi - 1] == letter) and not (
|
||||
pas[lo - 1] == letter and pas[hi - 1] == letter
|
||||
):
|
||||
r += 1
|
||||
print(r)
|
||||
|
||||
|
||||
def main():
|
||||
data = get_data(__file__)
|
||||
part_1(data)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user