First attempt at a faster / more efficient implementation. This is orders of magnitude faster than the first, but still not nearly fast enough.
This commit is contained in:
parent
fbd7c8fb00
commit
5d4757d4cb
4 changed files with 102 additions and 0 deletions
|
@ -40,3 +40,21 @@ func ParseInput(data []string) (map[int]bool, []*Rule) {
|
|||
|
||||
return plants, rules
|
||||
}
|
||||
|
||||
// The function isn't fast, the resulting data is.
|
||||
func FastParseInput(data []string) ([]byte, map[string]byte) {
|
||||
stateStrings := strings.Split(data[0], " ")
|
||||
ruleStrings := data[2:]
|
||||
|
||||
// Populate plant list
|
||||
plants := []byte(stateStrings[len(stateStrings)-1])
|
||||
|
||||
// Create rules
|
||||
rules := make(map[string]byte)
|
||||
for _, ruleStr := range ruleStrings {
|
||||
ruleData := strings.Split(ruleStr, " ")
|
||||
rules[ruleData[0]] = []byte(ruleData[2])[0]
|
||||
}
|
||||
|
||||
return plants, rules
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue