29 lines
510 B
Go
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
|
|
}
|