Day 8 part 1 solution.
This commit is contained in:
@ -5,6 +5,8 @@ import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ReadInput isn't here to make friends. It is highly specific to this domain.
|
||||
@ -25,7 +27,7 @@ func ReadInput() []string {
|
||||
return lines
|
||||
}
|
||||
|
||||
// ReadInputS is like ReadInput, but returns a byte array.
|
||||
// ReadInputBytes is like ReadInput, but returns a byte array.
|
||||
func ReadInputBytes() []byte {
|
||||
rawData, err := ioutil.ReadFile(os.Args[1])
|
||||
|
||||
@ -35,3 +37,26 @@ func ReadInputBytes() []byte {
|
||||
|
||||
return bytes.TrimRight(rawData, "\n")
|
||||
}
|
||||
|
||||
// ReadInputInts is like ReadInput, but returns an array of ints. (space-separated in the input)
|
||||
func ReadInputInts() []int {
|
||||
rawData, err := ioutil.ReadFile(os.Args[1])
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
strData := strings.Split(strings.TrimSpace(string(rawData)), " ")
|
||||
data := []int{}
|
||||
for _, newIntStr := range strData {
|
||||
newInt, err := strconv.Atoi(newIntStr)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
data = append(data, newInt)
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
|
Reference in New Issue
Block a user