Skip to content

Commit

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

patterns = set()
combinations = set()

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

foundGoodCombo = False
for pattern in patterns:
if combo.startswith(pattern):
remainingCombo = combo.replace(pattern, '', 1)
foundGoodCombo = foundGoodCombo or testComboIsValid(remainingCombo)
return foundGoodCombo

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:
if testComboIsValid(combo):
counter += 1

print(counter)
10 changes: 10 additions & 0 deletions 2024/19/testinput.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
r, wr, b, g, bwu, rb, gb, br

brwrr
bggr
gbbr
rrbgbr
ubwu
bwurrg
brgr
bbrgwb

0 comments on commit cfed047

Please sign in to comment.