14
https://adventofcode.com/2024/day/14
Prob1
python
import sys
second = int(sys.argv[1])
bots = []
w = 101
mx = (w-1)//2
h = 103
my = (h-1)//2
q = [0, 0, 0, 0]
for line in sys.stdin:
print(line)
p_str, v_str = line.strip().split(' ')
px, py = map(int, p_str.removeprefix('p=').split(','))
vx, vy = map(int, v_str.removeprefix('v=').split(','))
px = (px + vx*second) % w
py = (py + vy*second) % h
print(px, py)
if px > mx and py > my:
q[0] += 1
elif px < mx and py > my:
q[1] += 1
elif px < mx and py < my:
q[2] += 1
elif px > mx and py < my:
q[3] += 1
print(q)
print(q[0]*q[1]*q[2]*q[3])
Prob2
python
import sys
bots = []
w = 101
h = 103
for line in sys.stdin:
p_str, v_str = line.strip().split(' ')
px, py = map(int, p_str.removeprefix('p=').split(','))
vx, vy = map(int, v_str.removeprefix('v=').split(','))
bots.append((px, py, vx, vy))
for i in range(1000000):
for i, (px, py, vx, vy) in enumerate(bots):
px += vx
py += vy
px %= w
py %= h
bots[i] = (px, py, vx, vy)
dd = [[' ']*w for j in range(h)]
for (px, py, vx, vy) in bots:
dd[py][px] = '*'
for d in dd:
print(''.join(d))