AoC2020/helper/readFile.go

37 lines
670 B
Go
Raw Normal View History

2020-12-02 17:47:40 +01:00
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
}
2020-12-04 17:45:16 +01:00
func GetFile(filename string) (string, error) {
content, err := ioutil.ReadFile(filename)
if err != nil {
return "", err
}
return string(content), err
}
2020-12-02 17:47:40 +01:00
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
}