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:
Anna Rose Wiggins 2018-12-13 00:27:02 -05:00
parent fbd7c8fb00
commit 5d4757d4cb
No known key found for this signature in database
GPG key ID: 8D9ACA841015C59A
4 changed files with 102 additions and 0 deletions

View file

@ -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
}