Solution for 12.1.
This commit is contained in:
parent
2d71871cf4
commit
fbd7c8fb00
4 changed files with 163 additions and 0 deletions
42
2018/internal/day12/input.go
Normal file
42
2018/internal/day12/input.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue