code.go 750 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package main
  2. import (
  3. "bufio"
  4. "fmt"
  5. "log"
  6. "os"
  7. )
  8. var directions [][]int = [][]int{
  9. {0, -1}, {1, 0}, {0, 1}, {-1, 0},
  10. }
  11. type Point struct {
  12. x, y int
  13. direction int
  14. }
  15. func (p *Point) key() string {
  16. return fmt.Sprintf("%d_%d", p.x, p.y)
  17. }
  18. func readInput(file *os.File) [][]byte {
  19. scanner := bufio.NewScanner(file)
  20. var matrix [][]byte
  21. for scanner.Scan() {
  22. line := scanner.Text()
  23. if line == "" {
  24. break
  25. }
  26. matrix = append(matrix, []byte(line))
  27. }
  28. return matrix
  29. }
  30. func main() {
  31. if len(os.Args) < 2 {
  32. log.Fatal("You need to specify a file!")
  33. }
  34. filePath := os.Args[1]
  35. file, err := os.Open(filePath)
  36. if err != nil {
  37. log.Fatalf("Failed to open %s!\n", filePath)
  38. }
  39. matrix := readInput(file)
  40. fmt.Println(matrix)
  41. }