adventofcode/2018/day24/day24.go

64 lines
1.0 KiB
Go
Raw Normal View History

2018-12-16 07:26:17 +00:00
package main
2019-11-07 23:20:20 +00:00
import (
"bufio"
"fmt"
"os"
)
2018-12-16 07:26:17 +00:00
2019-11-07 23:20:20 +00:00
const (
2019-11-08 17:52:19 +00:00
Debug = true
2019-11-07 23:20:20 +00:00
)
2018-12-16 07:26:17 +00:00
func main() {
2019-11-07 23:20:20 +00:00
inp := StdinToStringSlice()
immune, infect := ParseInput(inp)
2019-11-08 17:52:19 +00:00
b := NewBattle(immune, infect)
//for !b.IsOver() {
if Debug {
b.PrintStatus()
fmt.Println("")
}
b.Fight()
//}
fmt.Println("")
fmt.Println("The battle is over!")
b.PrintStatus()
2019-11-07 23:20:20 +00:00
}
2019-11-08 17:52:19 +00:00
func ParseInput(inp []string) ([]*Army, []*Army) {
var immune, infection []*Army
var tp, id int
2019-11-07 23:20:20 +00:00
for _, v := range inp {
if v == "" {
continue
}
if v == "Immune System:" {
2019-11-08 17:52:19 +00:00
tp, id = ArmyTypeImmune, 0
2019-11-07 23:20:20 +00:00
continue
} else if v == "Infection:" {
2019-11-08 17:52:19 +00:00
tp, id = ArmyTypeInfection, 0
2019-11-07 23:20:20 +00:00
continue
}
2019-11-08 17:52:19 +00:00
id++
2019-11-07 23:20:20 +00:00
switch tp {
case ArmyTypeImmune:
2019-11-08 17:52:19 +00:00
immune = append(immune, NewArmy(v, tp, id))
2019-11-07 23:20:20 +00:00
case ArmyTypeInfection:
2019-11-08 17:52:19 +00:00
infection = append(infection, NewArmy(v, tp, id))
2019-11-07 23:20:20 +00:00
}
}
return immune, infection
2018-12-16 07:26:17 +00:00
}
2019-11-07 23:20:20 +00:00
func StdinToStringSlice() []string {
var input []string
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
input = append(input, scanner.Text())
}
return input
2018-12-16 07:26:17 +00:00
}