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

5
2023/1/obfuscated.py Normal file
View file

@ -0,0 +1,5 @@
import re
d="zero|one|two|three|four|five|six|seven|eight|nine|\\d)"
def f(l,p):
m=re.search(p,l)[1];return str(d.split("|").index(m)) if m in d else m
print(sum(map(lambda l:int(f(l,f"({d}.*")+f(l,".*("+d)),open(0).readlines())))

30
2023/1/script.py Normal file
View file

@ -0,0 +1,30 @@
#!/usr/bin/env python3
import re
digits = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
group = "|".join(digits + ["[0-9]"])
tot = 0
with open("lines.txt") as lines:
for line in lines.readlines():
print()
line = line.rstrip()
print(line)
last = re.search(rf"^.*({group})", line)
first = re.search(rf"({group}).*$", line)
print(first, last)
f = first[1]
l = last[1]
print(f, l)
if f in digits:
f = str(digits.index(f))
if l in digits:
l = str(digits.index(l))
print(f, l)
numb = int(f + l)
tot += numb
print(numb)
print()
print(tot)

28
2023/2/one.py Normal file
View file

@ -0,0 +1,28 @@
maxs = {"red": 12, "green": 13, "blue": 14}
gid = 0
possible_gid_sum = 0
with open("input") as lines:
for line in lines.readlines():
gid += 1
line = line.rstrip()
game_full, sets = line.split(":")
game, gid_str = game_full.split(" ")
assert int(gid_str) == gid
possible = True
for seet in sets.split(";"):
gcs = {"red": 0, "green": 0, "blue": 0}
for color in seet.split(","):
amount_str, color = color.strip().split(" ")
amount = int(amount_str)
gcs[color] += amount
for color, amount in gcs.items():
max = maxs[color]
if amount > max:
possible = False
if possible:
possible_gid_sum += gid
print(gid, possible)
print(possible_gid_sum)

24
2023/2/two.py Normal file
View file

@ -0,0 +1,24 @@
maxs = {"red": 12, "green": 13, "blue": 14}
gid = 0
power_sum = 0
with open("input") as lines:
for line in lines.readlines():
gid += 1
line = line.rstrip()
game_full, sets = line.split(":")
game, gid_str = game_full.split(" ")
assert int(gid_str) == gid
possible = True
gcs = {"red": 0, "green": 0, "blue": 0}
for seet in sets.split(";"):
for color in seet.split(","):
amount_str, color = color.strip().split(" ")
amount = int(amount_str)
gcs[color] = max(amount, gcs[color])
power = gcs["red"] * gcs["green"] * gcs["blue"]
print(gid, power)
power_sum += power
print(power_sum)

16
2023/24/one.py Normal file
View file

@ -0,0 +1,16 @@
#!/usr/bin/env python3
import sys
input_file = sys.argv[1]
hailstones = []
with open(input_file) as fd:
for line in fd.readlines():
line = line.rstrip()
line.replace("@", ",")
hailstone = [int(h) for h in line.split(",")]
hailstones.append(hailstone)

41
2023/3/one.py Normal file
View file

@ -0,0 +1,41 @@
#!/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])
sum = 0
for i in range(height):
line = lines[i]
pn_str = ""
for j in range(width):
c = line[j]
# print(19, c)
if c.isnumeric():
if not pn_str:
left = j
pn_str += c
# print(20, c, pn_str)
if pn_str and (j == width - 1 or not line[j + 1].isnumeric()):
print(25, pn_str)
adj = False
for ii in range(max(i - 1, 0), min(i + 1, height - 1) + 1):
for jj in range(max(left - 1, 0), min(j + 1, width - 1) + 1):
cc = lines[ii][jj]
print(ii, jj, cc)
if not cc.isnumeric() and cc != ".":
print("!")
adj = True
# print(pn_str, adj)
if adj:
pn = int(pn_str)
sum += pn
pn_str = ""
print(sum)

42
2023/3/two.py Normal file
View file

@ -0,0 +1,42 @@
#!/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])
gears = dict()
sum = 0
for i in range(height):
line = lines[i]
pn_str = ""
for j in range(width):
c = line[j]
# print(19, c)
if c.isnumeric():
if not pn_str:
left = j
pn_str += c
# print(20, c, pn_str)
if pn_str and (j == width - 1 or not line[j + 1].isnumeric()):
for ii in range(max(i - 1, 0), min(i + 1, height - 1) + 1):
for jj in range(max(left - 1, 0), min(j + 1, width - 1) + 1):
cc = lines[ii][jj]
# print(ii, jj, cc)
if cc == "*":
gears.setdefault((ii, jj), list())
gears[(ii, jj)].append(int(pn_str))
pn_str = ""
for gear_numbers in gears.values():
if len(gear_numbers) != 2:
continue
gear_ratio = gear_numbers[0] * gear_numbers[1]
sum += gear_ratio
print(sum)