FADZCXCSDYFHN5WAO2VKOZ6XGNTUZPSOPYTZCGC3VEYOSPSKXBHQC
package main
import (
"log"
)
const (
p1s = 7
p2s = 9
maxScore = 1000
)
type player struct {
pos int
score int
}
func main() {
if err := myMain(); err != nil {
log.Println(err)
}
}
func myMain() error {
log.Println(solveFirst())
return nil
}
func solveFirst() int {
p1 := player{pos: p1s}
p2 := player{pos: p2s}
dice := 1
var round int
for round = 1; ; round++ {
// payer 1
p1.addScore(dice)
dice += 3
if p1.score >= maxScore {
break
}
// player 2
p2.addScore(dice)
dice += 3
if p2.score >= maxScore {
break
}
}
if p1.score >= maxScore {
return p2.score * (6*round - 3)
} else {
return p1.score * 6 * round
}
}
func (p *player) addScore(dice int) {
p.pos += dice + dice + 1 + dice + 2
if p.pos%10 == 0 {
p.score += 10
} else {
p.score += p.pos % 10
}
}
module main
go 1.17