adventofcode/helpers.go
2016-12-15 08:36:57 -06:00

55 lines
839 B
Go

package aoc
import (
"bufio"
"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 atoi(i string) int {
var ret int
var err error
if ret, err = strconv.Atoi(i); err != nil {
log.Fatal("Invalid Atoi")
}
return ret
}
func itoa(i int) string {
return strconv.Itoa(i)
}
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)
}
func ClearScreen() {
fmt.Print("\033[H\033[2J")
}