use ParseIntList from common package
This commit is contained in:
parent
4b8792fed4
commit
bec8830fb6
1 changed files with 6 additions and 32 deletions
|
@ -2,9 +2,9 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"codeflow.dananglin.me.uk/apollo/advent-of-code/internal/common"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -61,42 +61,16 @@ func parseSeedNums(seedStr string) ([]int, error) {
|
|||
|
||||
seedStr = seedStr[strings.Index(seedStr, ":")+1:]
|
||||
|
||||
seeds := []int{}
|
||||
seedNum := ""
|
||||
|
||||
addSeed := func(digit string) error {
|
||||
value, err := strconv.Atoi(digit)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to convert %q to int; %w", digit, err)
|
||||
}
|
||||
seeds = append(seeds, value)
|
||||
return nil
|
||||
}
|
||||
|
||||
for ind, s := range seedStr {
|
||||
if unicode.IsDigit(s) {
|
||||
seedNum = seedNum + string(s)
|
||||
if ind == len(seedStr)-1 {
|
||||
if err := addSeed(seedNum); err != nil {
|
||||
return nil, fmt.Errorf("unable to add %q to seeds; %w", seedNum, err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if len(seedNum) > 0 {
|
||||
if err := addSeed(seedNum); err != nil {
|
||||
return nil, fmt.Errorf("unable to add %q to seeds; %w", seedNum, err)
|
||||
}
|
||||
}
|
||||
|
||||
seedNum = ""
|
||||
}
|
||||
seeds, err := common.ParseIntList(seedStr)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to parse the seed numbers from %q; %w", seedStr, err)
|
||||
}
|
||||
|
||||
return seeds, nil
|
||||
}
|
||||
|
||||
func parseMap(mapLines []string) (map[int]int, error) {
|
||||
var mapMatrix [][]int
|
||||
//var mapMatrix [][]int
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue