Started with 2020 because I need stars for Beeminder

This commit is contained in:
2024-08-19 09:42:10 -04:00
parent 6b0d7057d1
commit 04d8c44d66
6 changed files with 108 additions and 0 deletions

34
2020/d2.py Normal file
View 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()