AdventOfCode/2024/25/solution.py

66 lines
1.9 KiB
Python
Raw Normal View History

2024-12-25 12:10:22 +01:00
#!/bin/python3
import sys,time,re
from pprint import pprint
sys.path.insert(0, '../../')
from fred import list2int,get_re,nprint,lprint,loadFile
start_time = time.time()
input_f = 'input'
#########################################
# #
# Part 1 #
# #
#########################################
def part1():
instructions = []
with open(input_f) as file:
for line in file:
instructions.append(list(line.rstrip()))
keys = []
locks = []
for i in range(0,len(instructions),8):
tmp = []
# lock
if instructions[i] == list('#####'):
for l in range(5):
tmp.append(sum(element == '#' for element in [row[l] for row in instructions[i:i+7]])-1)
if tmp not in locks:
locks.append(tmp)
# key
elif instructions[i] == list('.....'):
for l in range(5):
tmp.append(sum(element == '#' for element in [row[l] for row in instructions[i:i+7]])-1)
if tmp not in keys:
keys.append(tmp)
fits = 0
works = True
for k in keys:
for l in locks:
for i in range(5):
if k[i] + l[i] > 5:
works = False
if works:
fits += 1
works = True
return fits
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')