Browse Source

Able to read input

Piotr Czajkowski 2 years ago
parent
commit
bcf5f157ed
2 changed files with 40 additions and 0 deletions
  1. 28 0
      03/code.go
  2. 12 0
      03/testinput

+ 28 - 0
03/code.go

@@ -0,0 +1,28 @@
+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")
+	return lines
+}
+
+func main() {
+	if len(os.Args) < 2 {
+		log.Fatal("You need to provide path to input file!")
+	}
+
+	lines := readInput(os.Args[1])
+	fmt.Println(lines)
+}

+ 12 - 0
03/testinput

@@ -0,0 +1,12 @@
+00100
+11110
+10110
+10111
+10101
+01111
+00111
+11100
+10000
+11001
+00010
+01010