Skip to content

Commit

Permalink
adding day25 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
Fadi88 committed Dec 25, 2024
1 parent dfff077 commit 7e2b65c
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions 2024/day25/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Any
import os
from time import perf_counter_ns
from itertools import product

input_file = os.path.join(os.path.dirname(__file__), "input.txt")
# input_file = os.path.join(os.path.dirname(__file__), "test.txt")
Expand All @@ -24,18 +25,35 @@ def wrapper_method(*args: Any, **kwargs: Any) -> Any:
return wrapper_method


def get_vals(d):
ret = []
for i in range(len(d[0])):
col = [l[i] for l in d]
ret.append(col.count("#"))
return ret


@profiler
def part_1():
with open(input_file) as _f:
pass
with open(input_file) as f:
data = [l.splitlines() for l in f.read().split("\n\n")]

locks = [d for d in data if d[0].count(".") == 0]
keys = [d for d in data if d[-1].count(".") == 0]

@profiler
def part_2():
with open(input_file) as _f:
pass
h = len(locks[0])

locks = list(map(get_vals, locks))
keys = list(map(get_vals, keys))

t = 0

for k, l in product(keys, locks):
if all(k[i]+l[i] <= h for i in range(len(k))):
t += 1

print(t)


if __name__ == "__main__":
part_1()
part_2()

0 comments on commit 7e2b65c

Please sign in to comment.