Started with 2020 because I need stars for Beeminder

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

31
2020/d1.py Normal file
View File

@ -0,0 +1,31 @@
from lib import get_data, str_to_ints
def part_1(data):
xs = sorted(str_to_ints(data))
for i in range(len(xs)):
for j in range(i + 1, len(xs)):
a, b = xs[i], xs[j]
if a + b == 2020:
print(a * b)
if a + b > 2020:
break
for i in range(len(xs)):
for j in range(i + 1, len(xs)):
for k in range(j + 1, len(xs)):
a, b, c = xs[i], xs[j], xs[k]
if a + b + c == 2020:
print(a * b * c)
if a + b + c > 2020:
break
def main():
data = get_data(__file__)
part_1(data)
if __name__ == "__main__":
main()

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()

33
2020/d3.py Normal file
View File

@ -0,0 +1,33 @@
from lib import get_data, Grid2D
def part_1(data):
g = Grid2D(data)
pos = (0, 0)
r = 0
while pos[0] < g.n_rows:
if g[pos] == "#":
r += 1
pos = (pos[0] + 1, (pos[1] + 3) % g.n_cols)
print(r)
fr = 1
for dr, dc in [(1, 1), (1, 3), (1, 5), (1, 7), (2, 1)]:
pos = (0, 0)
r = 0
while pos[0] < g.n_rows:
if g[pos] == "#":
r += 1
pos = (pos[0] + dr, (pos[1] + dc) % g.n_cols)
fr *= r
print(fr)
def main():
data = get_data(__file__)
part_1(data)
if __name__ == "__main__":
main()

1
2020/lib.py Symbolic link
View File

@ -0,0 +1 @@
../lib.py

1
2020/monitor.py Symbolic link
View File

@ -0,0 +1 @@
../monitor.py

View File

@ -131,6 +131,14 @@ Solutions and utility script for Advent of Code challenges in Python.
- Day 19: 40:00 (Way too slow! Oversight error. Come on.)
- Day 20:
## AoC 2020
- Day 1: 2:48 (people weren't able to submit because of a website outage)
- Day 2: 4:47 (no leaderboard, you can tell it's getting faster)
- Day 3: 7:06 (way too slow, lol; time to take it seriously)
- Day 4:
## AoC 2022
Done with this. Overall everything is solvable. It's more about consistency