Files
2022-12-06 09:44:39 +01:00

66 lines
971 B
Go

package main
import (
"bufio"
"fmt"
"log"
"os"
)
// A and X = Rock 1 point
// B and Y = Paper 2 points
// C and Z = Scissors 3 points
// Victory = 6 points
// Draw = 3 points
// Lose = 0 points
// Total = sum of shape and outcome of the round
func main() {
file, err := os.Open("./input.txt")
if err != nil {
log.Fatal(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
var score int
for scanner.Scan() {
var opponent string
var shape string
var points int
fmt.Sscanf(scanner.Text(), "%s %s", &opponent, &shape)
switch opponent {
case "A":
switch shape {
case "X":
points = 4
case "Y":
points = 8
case "Z":
points = 3
}
case "B":
switch shape {
case "X":
points = 1
case "Y":
points = 5
case "Z":
points = 9
}
case "C":
switch shape {
case "X":
points = 7
case "Y":
points = 2
case "Z":
points = 6
}
}
score += points
}
fmt.Println(score)
}