Browse Source

Able to read input

Piotr Czajkowski 1 year ago
parent
commit
e1371be92e
1 changed files with 50 additions and 0 deletions
  1. 50 0
      23/code.go

+ 50 - 0
23/code.go

@@ -0,0 +1,50 @@
+package main
+
+import (
+	"bufio"
+	"fmt"
+	"log"
+	"os"
+)
+
+type Point struct {
+	y, x  int
+	steps int
+}
+
+func readInput(file *os.File) [][]byte {
+	scanner := bufio.NewScanner(file)
+	var board [][]byte
+
+	for scanner.Scan() {
+		line := scanner.Text()
+		if line == "" {
+			break
+		}
+
+		var row []byte
+		for i := range line {
+			row = append(row, line[i])
+		}
+
+		board = append(board, row)
+	}
+
+	return board
+}
+
+func main() {
+	if len(os.Args) < 2 {
+		log.Fatal("You need to specify a file!")
+	}
+
+	filePath := os.Args[1]
+	file, err := os.Open(filePath)
+	if err != nil {
+		log.Fatalf("Failed to open %s!\n", filePath)
+
+	}
+
+	board := readInput(file)
+	fmt.Println(board)
+}