AoC2020/helper/readFile.go
2020-12-02 17:47:40 +01:00

29 lines
510 B
Go

package helper
import (
"io/ioutil"
"strconv"
"strings"
)
func GetInput(filename string) ([]string, error) {
content, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
lines := strings.Split(string(content), "\n")
return lines, err
}
func MapToNumber(strings []string) ([]int, error) {
var numbers []int
for _, line := range strings {
number, err := strconv.Atoi(line)
if err != nil {
return numbers, err
}
numbers = append(numbers, number)
}
return numbers, nil
}