Split intcode-processor to it's own library, made day 2 work with it
This commit is contained in:
@@ -2,11 +2,11 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
helpers2017 "bitbucket.org/thezeez/advent-of-code-2017/helpers"
|
||||
)
|
||||
|
||||
type Battlefield map[int]Army
|
||||
@@ -48,11 +48,11 @@ func PrepareForBattle(input []string) (Battlefield, Initiative) {
|
||||
}
|
||||
|
||||
group := &Group{
|
||||
Units: helpers2017.IntOrPanic(description[descriptionCount]),
|
||||
HitPoints: helpers2017.IntOrPanic(description[descriptionHitPoints]),
|
||||
AttackDamage: helpers2017.IntOrPanic(description[descriptionDamage]),
|
||||
Units: Atoi(description[descriptionCount]),
|
||||
HitPoints: Atoi(description[descriptionHitPoints]),
|
||||
AttackDamage: Atoi(description[descriptionDamage]),
|
||||
AttackType: description[descriptionDamageType],
|
||||
Initiative: helpers2017.IntOrPanic(description[descriptionInitiative]),
|
||||
Initiative: Atoi(description[descriptionInitiative]),
|
||||
}
|
||||
|
||||
immunities := groupImmunities.FindStringSubmatch(line)
|
||||
@@ -159,3 +159,12 @@ func (b Battlefield) TotalUnits() int {
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
func Atoi(i string) int {
|
||||
var ret int
|
||||
var err error
|
||||
if ret, err = strconv.Atoi(i); err != nil {
|
||||
log.Fatal("Invalid Atoi")
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
Reference in New Issue
Block a user