1
0
Fork 0

refactor(helper): update module path and function names

- move `helper` package files to root `helper` directory
- update all helper imports
- rename `GetLines` to `getLines` for consistent naming convention

🤖
This commit is contained in:
Sebastian Mark 2024-12-02 20:51:34 +01:00
parent 39f1e7ae74
commit 999a4a8fa2
6 changed files with 10 additions and 8 deletions

View file

@ -1,9 +1,10 @@
package main
import (
"aoc2024/helper"
"fmt"
"sort"
"aoc/helper"
)
type list struct {

View file

@ -1,9 +1,10 @@
package main
import (
"aoc2024/helper"
"fmt"
"sort"
"aoc/helper"
)
type reports []report

View file

@ -1,3 +0,0 @@
module aoc2024
go 1.23.3

View file

@ -1,53 +0,0 @@
package helper
import (
"bufio"
"log"
"os"
"path/filepath"
"strconv"
"strings"
)
const INPUT_FILE = "input"
func GetLines() *bufio.Scanner {
wd, err := os.Getwd()
filePath := filepath.Join(wd, INPUT_FILE)
file, err := os.Open(filePath)
if err != nil {
log.Fatal(err)
}
return bufio.NewScanner(file)
}
func ReadLinesTwoIntSlices() (list_a []int, list_b []int) {
scanner := GetLines()
for scanner.Scan() {
parts := strings.Fields(scanner.Text())
value_a, _ := strconv.Atoi(parts[0])
value_b, _ := strconv.Atoi(parts[1])
list_a = append(list_a, value_a)
list_b = append(list_b, value_b)
}
return list_a, list_b
}
func ReadLinesToIntSlices() (lines [][]int) {
scanner := GetLines()
for scanner.Scan() {
string_line := strings.Fields(scanner.Text())
int_line := make([]int, len(string_line))
for i, val := range string_line {
int_line[i], _ = strconv.Atoi(val)
}
lines = append(lines, int_line)
}
return lines
}

View file

@ -1,9 +0,0 @@
package helper
func Abs(x int) int {
if x < 0 {
return -x
}
return x
}