Day 8 part 1 solution.

This commit is contained in:
2018-12-10 20:23:18 -05:00
parent 31f60eca0e
commit 4d567425a7
4 changed files with 108 additions and 1 deletions

View File

@ -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
}