adventofcode/helpers.go

51 lines
787 B
Go
Raw Normal View History

package aoc
import (
"bufio"
2016-12-09 15:59:13 +00:00
"fmt"
"log"
"os"
"strconv"
)
func stdinToStringSlice() []string {
var input []string
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
input = append(input, scanner.Text())
}
return input
}
func itoa(i int) string {
return strconv.Itoa(i)
}
func atoi(i string) int {
var ret int
var err error
if ret, err = strconv.Atoi(i); err != nil {
log.Fatal("Invalid Atoi")
}
return ret
}
2016-12-09 15:59:13 +00:00
func stdinToString() string {
var input string
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
input += scanner.Text()
}
return input
}
func fileToString(fn string) string {
var c []byte
c, err = ioutil.Readfile(filename)
if err != nil {
fmt.Println("Unable to read file: " + filename)
os.Exit(1)
}
return string(c)
}