Skip to content

Commit bccec0d

Browse files
committed
Giving up for now, more tomorrow
1 parent 37e1d7e commit bccec0d

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/2022/day03/main.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,22 @@ func Day03Of2022PartB(rucksacks []string) (int, error) {
6161
sort.Slice(strings.Split(itemsC, ""), func(i, j int) bool {
6262
return strings.Split(itemsC, "")[i] < strings.Split(itemsC, "")[j]
6363
})
64-
longest, second, third := longestArrays(itemsA, itemsB, itemsC)
65-
for _, item := range longest {
66-
if search(strings.Split(second, ""), string(item)) && search(strings.Split(third, ""), string(item)) {
67-
priorities += charToNumber(item)
64+
shortest, second, third := shortest(strings.Split(itemsA, ""), strings.Split(itemsB, ""), strings.Split(itemsC, ""))
65+
for _, item := range shortest {
66+
if search(second, item) && search(third, item) {
67+
priorities += charToNumber([]rune(item)[0])
6868
break
6969
}
7070
}
7171
}
7272
return priorities, nil
7373
}
7474

75-
func longestArrays(arr1, arr2, arr3 string) (string, string, string) {
76-
if len(arr1) >= len(arr2) && len(arr1) >= len(arr3) {
75+
func shortest(arr1, arr2, arr3 []string) ([]string, []string, []string) {
76+
if len(arr1) <= len(arr2) && len(arr1) <= len(arr3) {
7777
return arr1, arr2, arr3
7878
}
79-
if len(arr2) >= len(arr1) && len(arr2) >= len(arr3) {
79+
if len(arr2) <= len(arr1) && len(arr2) <= len(arr3) {
8080
return arr2, arr1, arr3
8181
}
8282
return arr3, arr1, arr2

0 commit comments

Comments
 (0)