-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaoc12.py
More file actions
67 lines (48 loc) · 988 Bytes
/
Copy pathaoc12.py
File metadata and controls
67 lines (48 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from collections import defaultdict
file_path = "data/aoc12.txt"
ex = """0:
###
##.
##.
1:
###
##.
.##
2:
.##
###
##.
3:
##.
###
##.
4:
###
#..
###
5:
###
.#.
###
4x4: 0 0 0 0 2 0
12x5: 1 0 1 0 2 2
12x5: 1 0 1 0 3 2"""
from math import prod
def process_text(file: str) -> tuple[list[int], list[list[int]]]:
areas = []
presents = []
for trees in file.split("\n\n")[-1:]:
for line in trees.split("\n"):
if line:
size, *nums = line.split()
area = prod([int(n) for n in size[:-1].split("x")])
areas.append(area)
presents.append(list(map(int, nums)))
return areas, presents
#################### TASK 1 ####################
with open(file_path, "r") as file:
# areas, presents = process_text(ex)
areas, presents = process_text(file.read())
ok = sum([int(sum(pr) * 7 <= a) for a, pr in zip(areas, presents)])
print(ok)
#################### TASK 2 ####################