add 2024/day1
This commit is contained in:
parent
b435fb5f63
commit
9cc8248821
4 changed files with 1098 additions and 0 deletions
39
2024/helper/input.go
Normal file
39
2024/helper/input.go
Normal file
|
@ -0,0 +1,39 @@
|
|||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue