#!/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() input_f = 'input' def loadFile(): colors = [] towels = [] with open(input_f) as file: for l,line in enumerate(file): if l == 0: colors = line.rstrip().replace(" ","").split(',') if l > 1: towels.append(line.rstrip()) return colors,towels ######################################### # # # Part 1 # # # ######################################### def part1(): def createRegex(colors): return '^(' + '|'.join(colors) + ')+$' colors,towels = loadFile() 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') ######################################### # # # Part 2 # # # ######################################### def part2(): return start_time = time.time() print('Part 2:',part2(), '\t\t', round((time.time() - start_time)*1000), 'ms')