feat: day 1 first part done
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
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("././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))
|
||||
}
|
||||
Reference in New Issue
Block a user