adventofcode/2022/day02/main.go

57 lines
941 B
Go

package main
import (
"fmt"
h "git.bullercodeworks.com/brian/adventofcode/helpers"
)
func main() {
inp := h.StdinToStringSlice()
fmt.Println("# Part 1")
fmt.Printf("Score: %d\n", part1(inp))
fmt.Println("# Part 2")
fmt.Printf("Score: %d\n", part2(inp))
}
func part1(input []string) int {
score := 0
for i := range input {
first, second := input[i][0], (input[i][2] - 23)
score += int(second - 'A' + 1)
switch second - first {
case 1, 254:
score += 6
case 0:
score += 3
}
}
return score
}
func part2(input []string) int {
score := 0
for i := range input {
against, to := input[i][0], input[i][2]
choose := byte(64)
switch to {
case 'X':
choose = (against - 1)
if choose < 'A' {
choose = 'C'
}
case 'Y':
score += 3
choose = against
case 'Z':
choose = (against + 1)
if choose > 'C' {
choose = 'A'
}
score += 6
}
score += int(choose - 64)
}
return score
}