Initial commit

This commit is contained in:
Geoffrey Frogeye 2024-12-25 12:58:02 +01:00
commit 97a4330bc0
Signed by: geoffrey
GPG key ID: C72403E7F82E6AD8
110 changed files with 7006 additions and 0 deletions

88
2024/14/one.py Normal file
View file

@ -0,0 +1,88 @@
#!/usr/bin/env python3
import functools
import re
import sys
input_file = sys.argv[1]
with open(input_file) as fd:
lines = [line.rstrip() for line in fd.readlines()]
vec = tuple[int, int]
poss: list[vec] = list()
vits: list[vec] = list()
for line in lines:
match = re.findall(r"(-?\d+)", line)
assert match
pos = int(match[0]), int(match[1])
vit = int(match[2]), int(match[3])
poss.append(pos)
vits.append(vit)
print(poss, vits)
def print_poss(poss: list[vec]) -> None:
viz = [[0] * width for _ in range(height)]
for pos in poss:
px, py = pos
viz[py][px] += 1
for line in viz:
print("".join([(str(c) if c > 0 else ".") for c in line]))
print()
# x→ y↓
if input_file == "input":
width = 101
height = 103
else:
width = 11
height = 7
if input_file == "demo1":
secs = 5
else:
secs = 100
print_poss(poss)
for s in range(secs):
for r, vit in enumerate(vits):
px, py = poss[r]
px += vit[0]
py += vit[1]
while px >= width:
px -= width
while py >= height:
py -= height
while px < 0:
px += width
while py < 0:
py += height
poss[r] = px, py
print(s)
print_poss(poss)
half_width = width // 2
half_height = height // 2
# <<<<<|>>>>>
# <= first quadrant
quadrants = [0, 0, 0, 0]
for pos in poss:
px, py = pos
q = 0
if px == half_width or py == half_height:
continue
if px > half_width:
q += 1
if py > half_height:
q += 2
quadrants[q] += 1
print(quadrants)
print(functools.reduce(int.__mul__, quadrants))

95
2024/14/two.py Normal file
View file

@ -0,0 +1,95 @@
#!/usr/bin/env python3
import functools
import re
import sys
input_file = sys.argv[1]
with open(input_file) as fd:
lines = [line.rstrip() for line in fd.readlines()]
vec = tuple[int, int]
poss: list[vec] = list()
vits: list[vec] = list()
for line in lines:
match = re.findall(r"(-?\d+)", line)
assert match
pos = int(match[0]), int(match[1])
vit = int(match[2]), int(match[3])
poss.append(pos)
vits.append(vit)
print(poss, vits)
def print_poss(poss: list[vec]) -> None:
stop = True
viz = [[0] * width for _ in range(height)]
for pos in poss:
px, py = pos
if viz[py][px] > 0:
stop = False
viz[py][px] += 1
if stop:
for line in viz:
print("".join([(str(c) if c > 0 else ".") for c in line]))
input()
# x→ y↓
if input_file == "input":
width = 101
height = 103
else:
width = 11
height = 7
if input_file == "demo1":
secs = 5
else:
secs = 100
print_poss(poss)
# for s in range(secs):
s = 0
while True:
s += 1
for r, vit in enumerate(vits):
px, py = poss[r]
px += vit[0]
py += vit[1]
while px >= width:
px -= width
while py >= height:
py -= height
while px < 0:
px += width
while py < 0:
py += height
poss[r] = px, py
print(s)
print_poss(poss)
#
#
# half_width = width // 2
# half_height = height // 2
# # <<<<<|>>>>>
# # <= first quadrant
#
# quadrants = [0, 0, 0, 0]
# for pos in poss:
# px, py = pos
# q = 0
# if px == half_width or py == half_height:
# continue
# if px > half_width:
# q += 1
# if py > half_height:
# q += 2
# quadrants[q] += 1
#
# print(quadrants)
# print(functools.reduce(int.__mul__, quadrants))

96
2024/14/two_extra.py Normal file
View file

@ -0,0 +1,96 @@
#!/usr/bin/env python3
import functools
import re
import sys
input_file = sys.argv[1]
with open(input_file) as fd:
lines = [line.rstrip() for line in fd.readlines()]
vec = tuple[int, int]
poss: list[vec] = list()
vits: list[vec] = list()
for line in lines:
match = re.findall(r"(-?\d+)", line)
assert match
pos = int(match[0]), int(match[1])
vit = int(match[2]), int(match[3])
poss.append(pos)
vits.append(vit)
print(poss, vits)
def print_poss(poss: list[vec]) -> None:
stop = False
viz = [[0] * width for _ in range(height)]
for pos in poss:
px, py = pos
viz[py][px] += 1
for line in viz:
lin = "".join([(str(c) if c > 0 else ".") for c in line])
print(lin)
if "111111111" in lin:
stop = True
if stop:
input()
# x→ y↓
if input_file.startswith("input"):
width = 101
height = 103
else:
width = 11
height = 7
if input_file == "demo1":
secs = 5
else:
secs = 100
print_poss(poss)
# for s in range(secs):
s = 0
while True:
s += 1
for r, vit in enumerate(vits):
px, py = poss[r]
px += vit[0]
py += vit[1]
while px >= width:
px -= width
while py >= height:
py -= height
while px < 0:
px += width
while py < 0:
py += height
poss[r] = px, py
print(s)
print_poss(poss)
#
#
# half_width = width // 2
# half_height = height // 2
# # <<<<<|>>>>>
# # <= first quadrant
#
# quadrants = [0, 0, 0, 0]
# for pos in poss:
# px, py = pos
# q = 0
# if px == half_width or py == half_height:
# continue
# if px > half_width:
# q += 1
# if py > half_height:
# q += 2
# quadrants[q] += 1
#
# print(quadrants)
# print(functools.reduce(int.__mul__, quadrants))