Skip to content

Commit

Permalink
Solve part b
Browse files Browse the repository at this point in the history
  • Loading branch information
arunsathiya committed Jan 2, 2024
1 parent 96fdbf4 commit 78ec709
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/2022/day03/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,17 @@ func Day03Of2022PartB(rucksacks []string) (int, error) {
}
for _, group := range groups {
itemsA, itemsB, itemsC := group[0], group[1], group[2]
sort.Slice(strings.Split(itemsA, ""), func(i, j int) bool {
return strings.Split(itemsA, "")[i] < strings.Split(itemsA, "")[j]
arrA, arrB, arrC := strings.Split(itemsA, ""), strings.Split(itemsB, ""), strings.Split(itemsC, "")
sort.Slice(arrA, func(i, j int) bool {
return arrA[i] < arrA[j]
})
sort.Slice(strings.Split(itemsB, ""), func(i, j int) bool {
return strings.Split(itemsB, "")[i] < strings.Split(itemsB, "")[j]
sort.Slice(arrB, func(i, j int) bool {
return arrB[i] < arrB[j]
})
sort.Slice(strings.Split(itemsC, ""), func(i, j int) bool {
return strings.Split(itemsC, "")[i] < strings.Split(itemsC, "")[j]
sort.Slice(arrC, func(i, j int) bool {
return arrC[i] < arrC[j]
})
shortest, second, third := shortest(strings.Split(itemsA, ""), strings.Split(itemsB, ""), strings.Split(itemsC, ""))
shortest, second, third := shortest(arrA, arrB, arrC)
for _, item := range shortest {
if search(second, item) && search(third, item) {
priorities += charToNumber([]rune(item)[0])
Expand Down

0 comments on commit 78ec709

Please sign in to comment.