38 lines
732 B
Go
38 lines
732 B
Go
package util
|
|
|
|
import (
|
|
"bufio"
|
|
"bytes"
|
|
"io/ioutil"
|
|
"os"
|
|
)
|
|
|
|
// ReadInput isn't here to make friends. It is highly specific to this domain.
|
|
// It assumes the first argument on the command-line is a file with input. It
|
|
// returns an array of strings containing the lines of that file.
|
|
func ReadInput() []string {
|
|
file, err := os.Open(os.Args[1])
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
lines := []string{}
|
|
scanner := bufio.NewScanner(file)
|
|
for scanner.Scan() {
|
|
lines = append(lines, scanner.Text())
|
|
}
|
|
|
|
return lines
|
|
}
|
|
|
|
// ReadInputS is like ReadInput, but returns a byte array.
|
|
func ReadInputBytes() []byte {
|
|
rawData, err := ioutil.ReadFile(os.Args[1])
|
|
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
return bytes.TrimRight(rawData, "\n")
|
|
}
|