mirror of
https://github.com/onyx-and-iris/aoc2023.git
synced 2024-11-21 18:00:47 +00:00
36 lines
543 B
Go
36 lines
543 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"bufio"
|
||
|
"log"
|
||
|
"os"
|
||
|
"strconv"
|
||
|
)
|
||
|
|
||
|
// readlines reads lines from stdin.
|
||
|
// it returns them as an array of strings
|
||
|
func readlines() []string {
|
||
|
lines := []string{}
|
||
|
|
||
|
scanner := bufio.NewScanner(os.Stdin)
|
||
|
for scanner.Scan() {
|
||
|
lines = append(lines, scanner.Text())
|
||
|
}
|
||
|
|
||
|
if err := scanner.Err(); err != nil {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
|
||
|
return lines
|
||
|
}
|
||
|
|
||
|
// mustConv converts string to int
|
||
|
// it will panic if an error occurs
|
||
|
func mustConv(s string) int {
|
||
|
n, err := strconv.Atoi(s)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
return n
|
||
|
}
|