Solve 2024 day 19
This commit is contained in:
parent
744dbb4ffc
commit
299f1cf2ff
30
2024/d19.py
Normal file
30
2024/d19.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
from lib import get_data
|
||||||
|
from functools import cache
|
||||||
|
|
||||||
|
data = get_data(__file__)
|
||||||
|
lines = data.splitlines()
|
||||||
|
patterns = set(lines[0].split(", "))
|
||||||
|
|
||||||
|
|
||||||
|
@cache
|
||||||
|
def valid(line):
|
||||||
|
if line == "":
|
||||||
|
return 1
|
||||||
|
r = 0
|
||||||
|
for j in range(1, len(line) + 1):
|
||||||
|
sub = line[:j]
|
||||||
|
if sub in patterns:
|
||||||
|
r += valid(line[j:])
|
||||||
|
return r
|
||||||
|
|
||||||
|
|
||||||
|
p1, p2 = 0, 0
|
||||||
|
lines = lines[2:]
|
||||||
|
for line in lines:
|
||||||
|
v = valid(line.strip())
|
||||||
|
if v > 0:
|
||||||
|
p1 += 1
|
||||||
|
p2 += v
|
||||||
|
|
||||||
|
print(p1)
|
||||||
|
print(p2)
|
@ -309,5 +309,6 @@ and focus. Of course, learning more algorithms and techniques helps.
|
|||||||
- Day 16: ` >24h 24941 0 >24h 20575 0`
|
- Day 16: ` >24h 24941 0 >24h 20575 0`
|
||||||
- Day 17: `17:34:16 23722 0 >24h 17778 0`
|
- Day 17: `17:34:16 23722 0 >24h 17778 0`
|
||||||
- Day 18: `14:35:01 20398 0 14:37:18 19550 0`
|
- Day 18: `14:35:01 20398 0 14:37:18 19550 0`
|
||||||
- Day 19:
|
- Day 19: `00:14:37 2001 0 00:19:43 1584 0`
|
||||||
|
- Day 20:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user