-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpart1.go
52 lines (50 loc) · 882 Bytes
/
part1.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"reflect"
"slices"
)
func doPartOne(input string) int {
hands := getHands(input, false)
Counter := func(H Hand) int {
C := map[int]int{}
for _, c := range H.hand {
C[c]++
}
res := []int{}
for _, v := range C {
res = append(res, v)
}
slices.Sort(res)
for _, S := range handscores {
if reflect.DeepEqual(res, S.hand) {
return S.strength
}
}
return 0
}
slices.SortFunc(hands, func(a, b Hand) int {
Ca := Counter(a)
Cb := Counter(b)
if Ca < Cb {
return -1
}
if Ca > Cb {
return 1
}
// If we get here, they have the same score, and so need to iterate through the cards
for i := 0; i < len(a.hand); i++ {
if a.hand[i] < b.hand[i] {
return -1
}
if a.hand[i] > b.hand[i] {
return 1
}
}
return 0
})
res := 0
for i, H := range hands {
res += (i + 1) * H.bid
}
return res
}