You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
836 B
Go

package utils
import (
"bufio"
"log"
"os"
"strconv"
"strings"
)
func ReadLines(fileName string) []string {
result := []string{}
file, err := os.Open(fileName)
if err != nil {
log.Fatal(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
result = append(result, scanner.Text())
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
return result
}
func ParseIntArray(s string, sep string) []int {
result := []int{}
var vals []string
if sep == " " {
vals = strings.Fields(strings.TrimSpace(s))
} else {
vals = strings.Split(strings.TrimSpace(s), sep)
}
for _, val := range vals {
n, _ := strconv.Atoi(val)
result = append(result, n)
}
return result
}
func IntPow(x int, y int) int {
result := 1
for i := 0; i < y; i++ {
result *= x
}
return result
}