code.go 743 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package main
  2. import (
  3. "bufio"
  4. "fmt"
  5. "log"
  6. "os"
  7. )
  8. type Point struct {
  9. y, x int
  10. value byte
  11. }
  12. func (p *Point) key() string {
  13. return fmt.Sprintf("%d_%d", p.y, p.x)
  14. }
  15. func readInput(file *os.File) [][]byte {
  16. scanner := bufio.NewScanner(file)
  17. var matrix [][]byte
  18. for scanner.Scan() {
  19. line := scanner.Text()
  20. if line == "" {
  21. break
  22. }
  23. matrix = append(matrix, []byte(line))
  24. }
  25. return matrix
  26. }
  27. var directions [][]int = [][]int{
  28. {0, -1}, {1, 0}, {0, 1}, {-1, 0},
  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. }