43 lines
741 B
Go
43 lines
741 B
Go
|
package day12
|
||
|
|
||
|
import (
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
func ParseInput(data []string) (map[int]bool, []*Rule) {
|
||
|
stateStrings := strings.Split(data[0], " ")
|
||
|
state := stateStrings[len(stateStrings)-1]
|
||
|
ruleStrings := data[2:]
|
||
|
|
||
|
// Populate plant map
|
||
|
plants := make(map[int]bool)
|
||
|
for i, byte := range []byte(state) {
|
||
|
if byte == '#' {
|
||
|
plants[i] = true
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Create rules
|
||
|
rules := []*Rule{}
|
||
|
for _, ruleStr := range ruleStrings {
|
||
|
ruleData := strings.Split(ruleStr, " ")
|
||
|
|
||
|
rule := &Rule{}
|
||
|
positions := []byte(ruleData[0])
|
||
|
|
||
|
for i := 0; i < 5; i++ {
|
||
|
rule.Positions[i] = positions[i] == '#'
|
||
|
}
|
||
|
|
||
|
if ruleData[2] == "#" {
|
||
|
rule.Result = true
|
||
|
} else {
|
||
|
rule.Result = false
|
||
|
}
|
||
|
|
||
|
rules = append(rules, rule)
|
||
|
}
|
||
|
|
||
|
return plants, rules
|
||
|
}
|