-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
day_03.py
58 lines (44 loc) · 1.08 KB
/
day_03.py
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
import string
import aoc_helper
from aoc_helper import (
Grid,
PrioQueue,
decode_text,
extract_ints,
frange,
irange,
iter,
list,
map,
range,
tail_call,
)
raw = aoc_helper.fetch(3, 2022)
def parse_raw():
return list(raw.splitlines()).mapped_each(
lambda i: (
(ord(i) - ord("a"))
if i in string.ascii_lowercase
else (ord(i) - ord("A") + 26)
)
+ 1
)
data = parse_raw()
def process_sack(sack):
first_half, second_half = sack[: len(sack) // 2], sack[len(sack) // 2 :]
for i in first_half:
if i in second_half:
return i
def part_one(data):
return data.mapped(process_sack).sum()
def part_two(data):
groups = data.chunked(3)
sum = 0
for first, second, third in groups:
for i in first:
if i in second and i in third:
sum += i
break
return sum
aoc_helper.lazy_submit(day=3, year=2022, solution=part_one, data=data)
aoc_helper.lazy_submit(day=3, year=2022, solution=part_two, data=data)