Skip to content

Commit

Permalink
19-2
Browse files Browse the repository at this point in the history
  • Loading branch information
koosvary committed Dec 19, 2024
1 parent cfed047 commit 4b57113
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions 2024/19/19-2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import functools

patterns = set()
combinations = set()

@functools.cache
def testComboIsValid(combo):
if len(combo) == 0:
return 1

goodCombosFound = 0
for pattern in patterns:
if combo.startswith(pattern):
remainingCombo = combo.replace(pattern, '', 1)
goodCombosFound += testComboIsValid(remainingCombo)
return goodCombosFound

with open('2024/19/input.txt') as f:
for i, line in enumerate(f):
line = line.strip()

if i == 0:
patterns = set(line.split(', '))
elif i == 1:
continue
else:
combinations.add(line)


counter = 0
for combo in combinations:
counter += testComboIsValid(combo)

print(counter)

0 comments on commit 4b57113

Please sign in to comment.