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

59
2024/4/one.py Normal file
View file

@ -0,0 +1,59 @@
#!/usr/bin/env python3
import sys
input_file = sys.argv[1]
with open(input_file) as fd:
lines = [line.rstrip() for line in fd.readlines()]
height = len(lines)
width = len(lines[0])
word = "XMAS"
directions = [
(0, 1),
(1, 1),
(1, 0),
(1, -1),
(0, -1),
(-1, -1),
(-1, 0),
(-1, 1),
]
arrows = ["➡️", "↘️", "⬇️", "↙️", "⬅️", "↖️", "⬆️", "↗️"]
assert len(directions) == len(set(directions))
viz = [["."] * width for i in range(height)]
count = 0
for i in range(height):
for j in range(width):
for direction in directions:
ii = i
jj = j
for letter in word:
if (
ii not in range(height)
or jj not in range(width)
or lines[ii][jj] != letter
):
break
ii += direction[0]
jj += direction[1]
else:
count += 1
# d = directions.index(direction)
# viz[i][j] = arrows[d]
ii = i
jj = j
for letter in word:
viz[ii][jj] = letter
ii += direction[0]
jj += direction[1]
for line in viz:
print("".join(line))
print(count)

27
2024/4/two.py Normal file
View file

@ -0,0 +1,27 @@
#!/usr/bin/env python3
import sys
input_file = sys.argv[1]
with open(input_file) as fd:
lines = [line.rstrip() for line in fd.readlines()]
height = len(lines)
width = len(lines[0])
count = 0
for i in range(1, height - 1):
for j in range(1, width - 1):
if lines[i][j] != "A":
continue
tl = lines[i - 1][j - 1]
br = lines[i + 1][j + 1]
tr = lines[i - 1][j + 1]
bl = lines[i + 1][j - 1]
if not ((tl, br) == ("M", "S") or (tl, br) == ("S", "M")) or not (
(tr, bl) == ("M", "S") or (tr, bl) == ("S", "M")
):
continue
count += 1
print(count)