36 lines
566 B
Go
36 lines
566 B
Go
package common
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
func Must[T any](obj T, err error) T {
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
func LoadInputs(input string) []string {
|
|
fmt.Println("Opening file...")
|
|
bytes := Must(os.ReadFile("/home/g3po/Projects/advent_of_code_2024/inputs/" + input))
|
|
content := strings.Split(string(bytes), "\n")
|
|
return content[:len(content)-1]
|
|
}
|
|
|
|
func SumIntArr(arr []int) int {
|
|
sum := 0
|
|
for _, v := range arr {
|
|
sum += v
|
|
}
|
|
return sum
|
|
}
|
|
|
|
func StrToInt(str string) int {
|
|
return Must(strconv.Atoi(str))
|
|
}
|