Solved 2024/22 P1

This commit is contained in:
2024-12-22 12:06:33 +01:00
parent 2f5a9630d2
commit 1b58a3c6d4
3 changed files with 321 additions and 4 deletions
+18 -4
View File
@@ -5,7 +5,7 @@ sys.path.insert(0, '../../')
from fred import list2int,get_re,nprint,bfs
start_time = time.time()
input_f = 'test'
input_f = 'input'
def loadFile():
colors = []
@@ -13,7 +13,7 @@ def loadFile():
with open(input_f) as file:
for l,line in enumerate(file):
if l == 0:
colors = line.rstrip().split(',')
colors = line.rstrip().replace(" ","").split(',')
if l > 1:
towels.append(line.rstrip())
return colors,towels
@@ -27,9 +27,23 @@ def loadFile():
def part1():
def createRegex(colors):
return '^(' + '|'.join(colors) + ')+$'
colors,towels = loadFile()
return
count = 0
r = createRegex(colors)
print(r)
regexObj = re.compile(r)
#print(towels)
for tdx, t in enumerate(towels):
match = re.match(regexObj,t)
if match:
count += 1
print(tdx)
return count
start_time = time.time()
print('Part 1:',part1(), '\t\t', round((time.time() - start_time)*1000), 'ms')