Browse Source

Read test input

Piotr Czajkowski 2 years ago
commit
43afd7d0b5
2 changed files with 47 additions and 0 deletions
  1. 37 0
      01/code.go
  2. 10 0
      01/testinput1

+ 37 - 0
01/code.go

@@ -0,0 +1,37 @@
+package main
+
+import (
+	"fmt"
+	"io/ioutil"
+	"log"
+	"strconv"
+	"strings"
+)
+
+func readInput(file string) []int {
+	content, err := ioutil.ReadFile(file)
+	if err != nil {
+		log.Fatal(err)
+	}
+
+	lines := strings.Split(string(content), "\n")
+	var input []int
+	for _, line := range lines {
+		if line == "" {
+			continue
+		}
+
+		if number, err := strconv.Atoi(line); err == nil {
+			input = append(input, number)
+		} else {
+			log.Fatal(err)
+		}
+	}
+
+	return input
+}
+
+func main() {
+	input := readInput("./testinput1")
+	fmt.Println(input)
+}

+ 10 - 0
01/testinput1

@@ -0,0 +1,10 @@
+199
+200
+208
+210
+200
+207
+240
+269
+260
+263