AdventOfCode/2024/19/solution.py

61 lines
1.5 KiB
Python
Raw Normal View History

2024-12-19 18:04:23 +01:00
#!/bin/python3
import sys,time,re
from pprint import pprint
sys.path.insert(0, '../../')
from fred import list2int,get_re,nprint,bfs
start_time = time.time()
2024-12-22 12:06:33 +01:00
input_f = 'input'
2024-12-19 18:04:23 +01:00
def loadFile():
colors = []
towels = []
with open(input_f) as file:
for l,line in enumerate(file):
if l == 0:
2024-12-22 12:06:33 +01:00
colors = line.rstrip().replace(" ","").split(',')
2024-12-19 18:04:23 +01:00
if l > 1:
towels.append(line.rstrip())
return colors,towels
#########################################
# #
# Part 1 #
# #
#########################################
def part1():
2024-12-22 12:06:33 +01:00
def createRegex(colors):
return '^(' + '|'.join(colors) + ')+$'
2024-12-19 18:04:23 +01:00
colors,towels = loadFile()
2024-12-22 12:06:33 +01:00
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
2024-12-19 18:04:23 +01:00
start_time = time.time()
print('Part 1:',part1(), '\t\t', round((time.time() - start_time)*1000), 'ms')
#########################################
# #
# Part 2 #
# #
#########################################
def part2():
return
start_time = time.time()
print('Part 2:',part2(), '\t\t', round((time.time() - start_time)*1000), 'ms')