2018 Day 24 Work
This commit is contained in:
parent
1ec6280623
commit
d8e15a5d51
@ -1,19 +1,104 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const ()
|
||||
const (
|
||||
ArmyTypeImmune = 1 << iota
|
||||
ArmyTypeInfection
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("vim-go")
|
||||
inp := StdinToStringSlice()
|
||||
immune, infect := ParseInput(inp)
|
||||
|
||||
}
|
||||
|
||||
func ParseInput(inp []string) ([]Army, []Army) {
|
||||
var immune, infection []Army
|
||||
var tp int
|
||||
for _, v := range inp {
|
||||
if v == "" {
|
||||
continue
|
||||
}
|
||||
if v == "Immune System:" {
|
||||
tp = ArmyTypeImmune
|
||||
continue
|
||||
} else if v == "Infection:" {
|
||||
tp = ArmyTypeInfection
|
||||
continue
|
||||
}
|
||||
switch tp {
|
||||
case ArmyTypeImmune:
|
||||
immune = append(immune, *NewArmy(v, tp))
|
||||
case ArmyTypeInfection:
|
||||
infection = append(infection, *NewArmy(v, tp))
|
||||
}
|
||||
}
|
||||
return immune, infection
|
||||
}
|
||||
|
||||
type AttackType int
|
||||
|
||||
type Army struct {
|
||||
tp int
|
||||
units int
|
||||
hp int
|
||||
immunities []string
|
||||
weaknesses []string
|
||||
damageType string
|
||||
strength int
|
||||
dam
|
||||
init int
|
||||
}
|
||||
|
||||
func NewArmy(inp string, tp int) *Army {
|
||||
a := new(Army)
|
||||
a.tp = tp
|
||||
|
||||
// Pull the parenthetical out, if one is there
|
||||
var prnth, other string
|
||||
var inPrnth bool
|
||||
var ptsOfOther int
|
||||
for _, v := range strings.Fields(inp) {
|
||||
if len(v) > 0 && v[len(v)-1] == ')' {
|
||||
prnth = prnth + " " + v
|
||||
inPrnth = false
|
||||
continue
|
||||
} else if len(v) > 0 && v[0] == '(' {
|
||||
inPrnth = true
|
||||
prnth = v
|
||||
continue
|
||||
}
|
||||
if inPrnth {
|
||||
prnth = prnth + " " + v
|
||||
} else {
|
||||
if len(other) > 0 {
|
||||
other = other + " "
|
||||
}
|
||||
other = other + v
|
||||
ptsOfOther++
|
||||
}
|
||||
}
|
||||
_, err := fmt.Sscanf(other, "%d units each with %d hit points with an attack that does %d %s damage at initiative %d", &a.units, &a.hp, &a.strength, &a.damageType, &a.init)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *Army) Power() int {
|
||||
return a.units * a.strength
|
||||
}
|
||||
|
||||
func StdinToStringSlice() []string {
|
||||
var input []string
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
for scanner.Scan() {
|
||||
input = append(input, scanner.Text())
|
||||
}
|
||||
return input
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user