-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (49 loc) · 970 Bytes
/
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
// -*- compile-command: "go run main.go ../example1.txt ../input.txt"; -*-
package main
import (
"flag"
"fmt"
"log"
. "github.com/gmlewis/advent-of-code-2021/enum"
"github.com/gmlewis/advent-of-code-2021/must"
)
var logf = log.Printf
var printf = fmt.Printf
func main() {
flag.Parse()
Each(flag.Args(), process)
}
func process(filename string) {
logf("Processing %v ...", filename)
games := must.ReadFileLines(filename)
// log.Printf("%v games", len(games))
scores := Map(games, scoreGame)
// log.Printf("%+v", scores)
totalScore := Sum(scores)
printf("Solution: %v\n", totalScore)
}
func scoreGame(game string) int {
switch game {
case "A X":
return 1 + 3
case "A Y":
return 2 + 6
case "A Z":
return 3 + 0
case "B X":
return 1 + 0
case "B Y":
return 2 + 3
case "B Z":
return 3 + 6
case "C X":
return 1 + 6
case "C Y":
return 2 + 0
case "C Z":
return 3 + 3
default:
log.Fatalf("bad game: %q", game)
}
return 0
}