Browse Source

Able to read input

Piotr Czajkowski 2 years ago
parent
commit
8e94f9de14
2 changed files with 47 additions and 0 deletions
  1. 38 0
      25/code.go
  2. 9 0
      25/testinput

+ 38 - 0
25/code.go

@@ -0,0 +1,38 @@
+package main
+
+import (
+	"fmt"
+	"io/ioutil"
+	"log"
+	"os"
+	"strings"
+)
+
+func readInput(file string) [][]string {
+	content, err := ioutil.ReadFile(file)
+	if err != nil {
+		log.Fatal(err)
+	}
+
+	lines := strings.Split(string(content), "\n")
+	var input [][]string
+	for _, line := range lines {
+		if line == "" {
+			continue
+		}
+
+		row := strings.Split(line, "")
+		input = append(input, row)
+	}
+
+	return input
+}
+
+func main() {
+	if len(os.Args) < 2 {
+		log.Fatal("Please provide a file name as argument")
+	}
+
+	input := readInput(os.Args[1])
+	fmt.Println(input)
+}

+ 9 - 0
25/testinput

@@ -0,0 +1,9 @@
+v...>>.vv>
+.vv>>.vv..
+>>.>v>...v
+>>v>>.>.v.
+v>v.vv.v..
+>.>>..v...
+.vv..>.>v.
+v.v..>>v.v
+....v..v.>