2022 Day3 Complete!

This commit is contained in:
Brian Buller 2022-12-03 07:14:41 -06:00
parent b9ab5f5787
commit e1bfbcde97
4 changed files with 520 additions and 0 deletions

300
2022/day03/input Normal file
View File

@ -0,0 +1,300 @@
lDDWVvlVVQfDMlWjGJTRjQCgTGLCLj
ZLZpwzLBhwZhSLBsjntGCtgJRjbnJgSG
qppdZzzsdsmZphrNsNwZhllDHLcVVDWFPvFWcWdFlv
ztdhgJDBJghmQtPFQPpmbw
lVlLRcnfllcfVcccGnSQVLcsTPFbpwsPFspTSqmbpswpbF
cCHRGcGcCRGlGrGcVGnrdWHWBDzBNhhQZWWNBhJz
NfnSSQpdnRSSpvWdSsjZDGNDjGDwTGTjHG
wlPzPqzPFbMmqPCFCJmbsjbHLDDHDZjDjbGHsT
gwMlgmtmPcqVVvhVnvcRnn
cBNBBCHhbhNhblBcCCvcBHSwTwDQSqRwDQpDRsjHST
dPmzMVWdmmMnnZJtZVdqjTSrjTjrpQrsTTVwQRSj
qzmZMmdZPtnGqclblGlbGvgBFc
ZfpmNDfRhzbbqDnD
SFtFjTTZVTFvVTjHrsVvqGBJqhnSSnbJznLGJwJq
TjdPPtdMPPWCcZgW
qsbmGCsjHNhmhmhzTDznpnlQZlbWlZ
LTSSfSvggVVgBgfLtvvtTSczzpWnZQZnlnzpBcnWpQWc
FrLvrrrVPgdPftSHHdNsjTHjmGThhm
wGQlMjvMwpvjvZjZTZlWjplWJJTggDTgfCnntPgTJPbtPgSP
qNhJmcVmdJqhHnPnDNtnPDCg
LrrchqhRdLVzRdmhJcFFQWGGMjpGlvZzlQQv
ZqZMbZMfQZptpjlF
PJCggvHlwWHvSSvCJNvSPvDBtFDQThFQjtRQhhFTsVThQtsF
PwWCnBBCClcMMznMdG
rNwwQJrJrnQswrQrRRwCShBSLndZpdnhpGFSdhBp
PvzzWVzbclGFhLFGdZll
VWjPWvbjcVbVcGVzjcgzgwQQRRRrqwRJQwwstCRR
zjBMMzznjbssrBrMBbvHDmrlprlrpwGp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ncrs
bPzRlMPTzTMldJMnhswcjzfQVccQhc
HCCqNmNmQQmQssJn
pHptprtgRStTtMJt
nTmhrsPMsTfmHHGcSgtj
bJJwdlrJQLlvwlQDDwSbgffGVNjfgjNtVbcf
QlpDQFJdvdFqJdFpLvDFpLLnzZMnBMRRzMTqnrzqTRPznz
qRVRqBzgwqRpqRgVqQRPpQJJPrPhPGJnsGrCFdFJrZdG
ZvWDmMvmSvCndssrsJ
WcZcNWlcMjBQpzNTqVBp
DpLPZLDDlcgmDmhVgfgfWWRwhwwt
VrVMdbCrrBTjCMQQtMwQNSqMQW
VCBHdJHdvrrFsbsdrBJTdTzZcpmZGDGPlmzmlccFDZDn

74
2022/day03/main.go Normal file
View File

@ -0,0 +1,74 @@
package main
import (
"fmt"
h "git.bullercodeworks.com/brian/adventofcode/helpers"
)
func main() {
inp := h.StdinToStringSlice()
fmt.Println("# Part 1")
fmt.Println(part1(inp))
fmt.Println("# Part 2")
fmt.Println(part2(inp))
}
func part1(inp []string) int {
var ret int
for i := range inp {
sack := inp[i]
c1, c2 := sack[:len(sack)/2], sack[len(sack)/2:]
var dupe byte
for _, c1w := range c1 {
for _, c2w := range c2 {
if c1w == c2w {
dupe = byte(c1w)
break
}
}
if dupe != 0 {
break
}
}
if dupe >= 'a' {
ret += int(dupe - 'a' + 1)
} else if dupe >= 'A' {
ret += int(dupe - 'A' + 27)
}
}
return ret
}
func part2(inp []string) int {
var ret int
elves := []string{"", "", ""}
for i := range inp {
elves[i%3] = inp[i]
if i%3 == 2 {
var badge byte
// Check 'em
for _, e1 := range elves[0] {
for _, e2 := range elves[1] {
for _, e3 := range elves[2] {
if e1 == e2 && e2 == e3 {
badge = byte(e1)
}
}
if badge != 0 {
break
}
}
if badge != 0 {
break
}
}
if badge >= 'a' {
ret += int(badge - 'a' + 1)
} else if badge >= 'A' {
ret += int(badge - 'A' + 27)
}
}
}
return ret
}

140
2022/day03/problem Normal file
View File

@ -0,0 +1,140 @@
Advent of Code
• [About]
• [Events]
• [Shop]
• [Settings]
• [Log Out]
br0xen (AoC++) 6*
      /*2022*/
• [Calendar]
• [AoC++]
• [Sponsors]
• [Leaderboard]
• [Stats]
Our sponsors help make Advent of Code possible:
Spotify - Follow our engineering blog to see how our developers solve complex tech problems, at scale, every day.
--- Day 3: Rucksack Reorganization ---
One Elf has the important job of loading all of the rucksacks with supplies for the jungle journey. Unfortunately, that
Elf didn't quite follow the packing instructions, and so a few items now need to be rearranged.
Each rucksack has two large compartments. All items of a given type are meant to go into exactly one of the two
compartments. The Elf that did the packing failed to follow this rule for exactly one item type per rucksack.
The Elves have made a list of all of the items currently in each rucksack (your puzzle input), but they need your help
finding the errors. Every item type is identified by a single lowercase or uppercase letter (that is, a and A refer to
different types of items).
The list of items for each rucksack is given as characters all on a single line. A given rucksack always has the same
number of items in each of its two compartments, so the first half of the characters represent items in the first
compartment, while the second half of the characters represent items in the second compartment.
For example, suppose you have the following list of contents from six rucksacks:
vJrwpWtwJgWrhcsFMMfFFhFp
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
ttgJtRGJQctTZtZT
CrZsJsPPZsGzwwsLwLmpwMDw
 The first rucksack contains the items vJrwpWtwJgWrhcsFMMfFFhFp, which means its first compartment contains the items
vJrwpWtwJgWr, while the second compartment contains the items hcsFMMfFFhFp. The only item type that appears in both
compartments is lowercase p.
 The second rucksack's compartments contain jqHRNqRjqzjGDLGL and rsFMfFZSrLrFZsSL. The only item type that appears in
both compartments is uppercase L.
 The third rucksack's compartments contain PmmdzqPrV and vPwwTWBwg; the only common item type is uppercase P.
 The fourth rucksack's compartments only share item type v.
 The fifth rucksack's compartments only share item type t.
 The sixth rucksack's compartments only share item type s.
To help prioritize item rearrangement, every item type can be converted to a priority:
 Lowercase item types a through z have priorities 1 through 26.
 Uppercase item types A through Z have priorities 27 through 52.
In the above example, the priority of the item type that appears in both compartments of each rucksack is 16 (p), 38
(L), 42 (P), 22 (v), 20 (t), and 19 (s); the sum of these is 157.
Find the item type that appears in both compartments of each rucksack. What is the sum of the priorities of those item
types?
Your puzzle answer was 7967.
--- Part Two ---
As you finish identifying the misplaced items, the Elves come to you with another issue.
For safety, the Elves are divided into groups of three. Every Elf carries a badge that identifies their group. For
efficiency, within each group of three Elves, the badge is the only item type carried by all three Elves. That is, if a
group's badge is item type B, then all three Elves will have item type B somewhere in their rucksack, and at most two of
the Elves will be carrying any other item type.
The problem is that someone forgot to put this year's updated authenticity sticker on the badges. All of the badges need
to be pulled out of the rucksacks so the new authenticity stickers can be attached.
Additionally, nobody wrote down which item type corresponds to each group's badges. The only way to tell which item type
is the right one is by finding the one item type that is common between all three Elves in each group.
Every set of three lines in your list corresponds to a single group, but each group can have a different badge item
type. So, in the above example, the first group's rucksacks are the first three lines:
vJrwpWtwJgWrhcsFMMfFFhFp
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
And the second group's rucksacks are the next three lines:
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
ttgJtRGJQctTZtZT
CrZsJsPPZsGzwwsLwLmpwMDw
In the first group, the only item type that appears in all three rucksacks is lowercase r; this must be their badges. In
the second group, their badge item type must be Z.
Priorities for these items must still be found to organize the sticker attachment efforts: here, they are 18 (r) for the
first group and 52 (Z) for the second group. The sum of these is 70.
Find the item type that corresponds to the badges of each three-Elf group. What is the sum of the priorities of those
item types?
Your puzzle answer was 2716.
Both parts of this puzzle are complete! They provide two gold stars: **
At this point, you should return to your Advent calendar and try another puzzle.
If you still want to see it, you can get your puzzle input.
You can also [Shareon Twitter Mastodon] this puzzle.
References
Visible links
. https://adventofcode.com/
. https://adventofcode.com/2022/about
. https://adventofcode.com/2022/events
. https://teespring.com/stores/advent-of-code
. https://adventofcode.com/2022/settings
. https://adventofcode.com/2022/auth/logout
. Advent of Code Supporter
https://adventofcode.com/2022/support
. https://adventofcode.com/2022
. https://adventofcode.com/2022
. https://adventofcode.com/2022/support
. https://adventofcode.com/2022/sponsors
. https://adventofcode.com/2022/leaderboard
. https://adventofcode.com/2022/stats
. https://adventofcode.com/2022/sponsors
. https://engineering.atspotify.com/
. https://en.wikipedia.org/wiki/Rucksack
. https://adventofcode.com/2022
. https://adventofcode.com/2022/day/3/input
. https://twitter.com/intent/tweet?text=I%27ve+completed+%22Rucksack+Reorganization%22+%2D+Day+3+%2D+Advent+of+Code+2022&url=https%3A%2F%2Fadventofcode%2Ecom%2F2022%2Fday%2F3&related=ericwastl&hashtags=AdventOfCode
. javascript:void(0);

6
2022/day03/testinput Normal file
View File

@ -0,0 +1,6 @@
vJrwpWtwJgWrhcsFMMfFFhFp
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
ttgJtRGJQctTZtZT
CrZsJsPPZsGzwwsLwLmpwMDw