2018 Day 24 Work

This commit is contained in:
2019-11-07 21:30:41 -06:00
parent d8e15a5d51
commit 4a7a0e872e
4 changed files with 326 additions and 53 deletions

View File

@@ -15,7 +15,11 @@ const (
func main() {
inp := StdinToStringSlice()
immune, infect := ParseInput(inp)
for _, v := range immune {
fmt.Println("++ ", v.immunities)
fmt.Println("-- ", v.weaknesses)
}
_, _ = immune, infect
}
func ParseInput(inp []string) ([]Army, []Army) {
@@ -42,58 +46,6 @@ func ParseInput(inp []string) ([]Army, []Army) {
return immune, infection
}
type AttackType int
type Army struct {
tp int
units int
hp int
immunities []string
weaknesses []string
damageType string
strength int
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)