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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
|
||||||
|
"codeflow.dananglin.me.uk/apollo/advent-of-code/internal/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -61,42 +61,16 @@ func parseSeedNums(seedStr string) ([]int, error) {
|
||||||
|
|
||||||
seedStr = seedStr[strings.Index(seedStr, ":")+1:]
|
seedStr = seedStr[strings.Index(seedStr, ":")+1:]
|
||||||
|
|
||||||
seeds := []int{}
|
seeds, err := common.ParseIntList(seedStr)
|
||||||
seedNum := ""
|
|
||||||
|
|
||||||
addSeed := func(digit string) error {
|
|
||||||
value, err := strconv.Atoi(digit)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to convert %q to int; %w", digit, err)
|
return nil, fmt.Errorf("unable to parse the seed numbers from %q; %w", seedStr, 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 = ""
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return seeds, nil
|
return seeds, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseMap(mapLines []string) (map[int]int, error) {
|
func parseMap(mapLines []string) (map[int]int, error) {
|
||||||
var mapMatrix [][]int
|
//var mapMatrix [][]int
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue