Day 3 - Advent of Code 2022 Hints
- First, we need to parse the input and store it in a convenient data structure. For example, we could split each rucksack’s items into two separate strings representing the items in the first and second compartments.
- Next, we need to find the item type that appears in both compartments of each rucksack. One way to do this is to iterate over the characters in each compartment and keep track of the ones that appear in both compartments.
- Once we have identified the common item type in each rucksack, we need to convert it to a priority. Lowercase letters have priorities 1 through 26, and uppercase letters have priorities 27 through 52.
- After we have converted each item type to its priority, we can sum up all the priorities to get the final result.
- Finally, we can print the result to the screen or return it from the function, depending on how the solution is implemented.
A pseudocode of this might be:
for each rucksack:
split rucksack into two compartments
for each item in first compartment:
for each item in second compartment:
if item from first compartment matches item from second compartment:
add priority of matching item to running total
print running total
To solve the second part of this challenge, we need to find the common item type between each group of three Elves. Since each group of three Elves carries the same badge item type, we can find this item type by comparing the items in each rucksack in the group.
The solution is similar to the first part, but it adds the additional step of comparing the items in each group of three rucksacks to find the common item type. It also uses a set to store the common items, which ensures that each item type is only added to the set once.
This solution can be implemented in any programming language that supports loops, string manipulation, and sets.