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

1
2024/19/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
colors

8
2024/19/colors.py Normal file
View file

@ -0,0 +1,8 @@
#!/usr/bin/env python3
import sys
input_file = sys.argv[1]
with open(input_file) as fd:
print(fd.read().replace("w", "").replace("u", "🟦").replace("b", "").replace("r", "🟥").replace("g", "🟩"))

28
2024/19/one.py Normal file
View file

@ -0,0 +1,28 @@
#!/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()]
towels = set(map(str.strip, lines[0].split(",")))
patterns = lines[2:]
def possible(pattern: str) -> bool:
if not pattern:
return True
for towel in towels:
if pattern.startswith(towel):
if possible(pattern[len(towel):]):
return True
return False
possible_count = 0
for pattern in patterns:
if possible(pattern):
possible_count += 1
print(possible_count)

32
2024/19/two.py Normal file
View file

@ -0,0 +1,32 @@
#!/usr/bin/env python3
import sys
import functools
input_file = sys.argv[1]
with open(input_file) as fd:
lines = [line.rstrip() for line in fd.readlines()]
towels = set(map(str.strip, lines[0].split(",")))
patterns = lines[2:]
@functools.cache
def possible(pattern: str) -> int:
if not pattern:
return 1
possible_count = 0
for towel in towels:
if pattern.startswith(towel):
possible_count += possible(pattern[len(towel) :])
return possible_count
possible_count = 0
for pattern in patterns:
res = possible(pattern)
print(27, pattern, res)
possible_count += res
print(possible_count)