diff --git a/2023/day-5/almanac.go b/2023/day-5/almanac.go index 841f819..88756d6 100644 --- a/2023/day-5/almanac.go +++ b/2023/day-5/almanac.go @@ -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 }