-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
68 lines (58 loc) · 1.17 KB
/
main.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
_ "embed"
"fmt"
"os"
"strings"
)
//go:embed input.txt
var input string
//go:embed input_test.txt
var inputTest string
func main() {
// Check argv if we use test input or not
if len(os.Args) > 1 && os.Args[1] == "test" {
input = inputTest
}
answer := doPartOne(input)
println(answer)
answer = doPartTwo(input)
println(answer)
}
type Hands []Hand
type Hand struct {
hand []int
bid int
}
type Score struct {
hand []int
strength int
}
var (
handscores = []Score{
{[]int{5}, 10}, {[]int{1, 4}, 9}, {[]int{2, 3}, 8}, {[]int{1, 1, 3}, 7},
{[]int{1, 2, 2}, 6}, {[]int{1, 1, 1, 2}, 5}, {[]int{1, 1, 1, 1, 1}, 4},
}
cardscore = map[rune]int{
'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7,
'8': 8, '9': 9, 'T': 10, 'J': 11, 'Q': 12, 'K': 13, 'A': 14,
}
)
func getHands(input string, p2 bool) Hands {
var hands Hands
for _, line := range strings.Split(strings.TrimSpace(input), "\n") {
var H string
var B int
fmt.Sscanf(line, "%s %d", &H, &B)
hand := []int{}
for _, c := range H {
n := cardscore[c]
if c == 'J' && p2 {
n = 1
}
hand = append(hand, n)
}
hands = append(hands, Hand{hand, B})
}
return hands
}