2024-12-01 18:43:58 +00:00
|
|
|
package helper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
const INPUT_FILE = "input"
|
|
|
|
|
2024-12-02 19:51:34 +00:00
|
|
|
func getLines() *bufio.Scanner {
|
2024-12-01 18:43:58 +00:00
|
|
|
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) {
|
2024-12-02 19:51:34 +00:00
|
|
|
scanner := getLines()
|
2024-12-01 18:43:58 +00:00
|
|
|
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
|
|
|
|
}
|
2024-12-02 12:30:04 +00:00
|
|
|
|
2024-12-02 17:19:40 +00:00
|
|
|
func ReadLinesToIntSlices() (lines [][]int) {
|
2024-12-02 19:51:34 +00:00
|
|
|
scanner := getLines()
|
2024-12-02 12:30:04 +00:00
|
|
|
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
|
|
|
|
}
|