116 lines
1.6 KiB
Go
116 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"embed"
|
|
"fmt"
|
|
"io/fs"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
//go:embed *
|
|
var input embed.FS
|
|
|
|
func part1() int {
|
|
data, err := fs.ReadFile(input, "input")
|
|
|
|
if err != nil {
|
|
fmt.Printf("ERROR: failed to read input: %s", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
score := 0
|
|
|
|
for _, game := range strings.Split(string(data), "\n") {
|
|
if game == "" {continue}
|
|
switch game{
|
|
case "A X":
|
|
score += 1
|
|
score += 3
|
|
case "A Y":
|
|
score += 2
|
|
score += 6
|
|
case "A Z":
|
|
score += 3
|
|
score += 0
|
|
case "B X":
|
|
score += 1
|
|
score += 0
|
|
case "B Y":
|
|
score += 2
|
|
score += 3
|
|
case "B Z":
|
|
score += 3
|
|
score += 6
|
|
case "C X":
|
|
score += 1
|
|
score += 6
|
|
case "C Y":
|
|
score += 2
|
|
score += 0
|
|
case "C Z":
|
|
score += 3
|
|
score += 3
|
|
}
|
|
}
|
|
return score
|
|
}
|
|
|
|
func part2() int {
|
|
data, err := fs.ReadFile(input, "input")
|
|
|
|
if err != nil {
|
|
fmt.Printf("ERROR: failed to read input: %s", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
score := 0
|
|
|
|
for _, game := range strings.Split(string(data), "\n") {
|
|
if game == "" {continue}
|
|
switch game{
|
|
// rock
|
|
case "A X":
|
|
score += 0
|
|
score += 3
|
|
case "A Y":
|
|
score += 3
|
|
score += 1
|
|
case "A Z":
|
|
score += 6
|
|
score += 2
|
|
|
|
// paper
|
|
case "B X":
|
|
score += 0
|
|
score += 1
|
|
case "B Y":
|
|
score += 3
|
|
score += 2
|
|
case "B Z":
|
|
score += 6
|
|
score += 3
|
|
|
|
// scissors
|
|
case "C X":
|
|
score += 0
|
|
score += 2
|
|
case "C Y":
|
|
score += 3
|
|
score += 3
|
|
case "C Z":
|
|
score += 6
|
|
score += 1
|
|
}
|
|
}
|
|
return score
|
|
}
|
|
|
|
func main() {
|
|
scoreOne := part1()
|
|
scoreTwo := part2()
|
|
|
|
fmt.Printf("The score on game one is %d\n", scoreOne)
|
|
fmt.Printf("The score on game two is %d\n", scoreTwo)
|
|
}
|