mirror of
https://github.com/onyx-and-iris/aoc2023.git
synced 2024-11-22 10:20:48 +00:00
32 lines
633 B
Go
32 lines
633 B
Go
|
package main
|
||
|
|
||
|
import log "github.com/sirupsen/logrus"
|
||
|
|
||
|
const (
|
||
|
highcard = iota // 0
|
||
|
onepair = iota // 1
|
||
|
twopair = iota // 2
|
||
|
threeofakind = iota // 3
|
||
|
fullhouse = iota // 4
|
||
|
fourofakind = iota // 5
|
||
|
fiveofakind = iota // 6
|
||
|
numKinds = iota
|
||
|
)
|
||
|
|
||
|
// one returns the sum of products of hand values by bids
|
||
|
func one(lines []string) (int, error) {
|
||
|
parselines(lines)
|
||
|
|
||
|
strength := []rune{'A', 'K', 'Q', 'J', 'T', '9', '8', '7', '6', '5', '4', '3', '2'}
|
||
|
log.Debug("strength: ", strength)
|
||
|
sortByKindAndStrength(strength)
|
||
|
|
||
|
sum := 0
|
||
|
|
||
|
for i, hand := range hands {
|
||
|
sum += (i + 1) * hand.bid
|
||
|
}
|
||
|
|
||
|
return sum, nil
|
||
|
}
|