Give it up for day 3 of (minimal :D) smooth brain shenanigans! https://pbs.twimg.com/media/E1bxikWWEAEGYHU.png
parent
3491af01a1
commit
041fbb83be
|
@ -0,0 +1,37 @@
|
|||
import aocd
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
puzzle_input = aocd.get_data(day=3, year=2022)
|
||||
|
||||
rucksacks = puzzle_input.split('\n')
|
||||
total_priority = 0
|
||||
badges_priority = 0
|
||||
|
||||
for r, rucksack in enumerate(rucksacks):
|
||||
|
||||
# Part 1 =================================================
|
||||
half_1 = set(rucksack[:len(rucksack)//2])
|
||||
half_2 = set(rucksack[len(rucksack)//2:])
|
||||
(in_both,) = half_1.intersection(half_2)
|
||||
if in_both.islower():
|
||||
total_priority = total_priority + ord(in_both) - 96
|
||||
else:
|
||||
total_priority = total_priority + ord(in_both) - 38
|
||||
|
||||
# Part 2 =================================================
|
||||
if (r+1)%3 == 0:
|
||||
rucksack_0prev = set(rucksack)
|
||||
rucksack_1prev = set(rucksacks[r-1])
|
||||
rucksack_2prev = set(rucksacks[r-2])
|
||||
(in_badge,) = rucksack_0prev & rucksack_1prev & rucksack_2prev
|
||||
print(in_badge)
|
||||
if in_badge.islower():
|
||||
badges_priority = badges_priority + ord(in_badge) - 96
|
||||
else:
|
||||
badges_priority = badges_priority + ord(in_badge) - 38
|
||||
|
||||
print(f'These elves are carrying a total of {total_priority:,} (prioritized?) things. That\'s a lotta stuff.')
|
||||
print(f'They\'re also v important with a total badge priority of {badges_priority:,}.')
|
||||
|
||||
|
Loading…
Reference in New Issue