code.go 554 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package main
  2. import (
  3. "fmt"
  4. "io/ioutil"
  5. "log"
  6. "os"
  7. "strings"
  8. )
  9. func readInput(file string) [][]string {
  10. content, err := ioutil.ReadFile(file)
  11. if err != nil {
  12. log.Fatal(err)
  13. }
  14. lines := strings.Split(string(content), "\n")
  15. var input [][]string
  16. for _, line := range lines {
  17. if line == "" {
  18. continue
  19. }
  20. row := strings.Split(line, "")
  21. input = append(input, row)
  22. }
  23. return input
  24. }
  25. func main() {
  26. if len(os.Args) < 2 {
  27. log.Fatal("Please provide a file name as argument")
  28. }
  29. input := readInput(os.Args[1])
  30. fmt.Println(input)
  31. }