1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package main
- import (
- "fmt"
- "io/ioutil"
- "log"
- "os"
- "strings"
- )
- type move struct {
- direction string
- steps int
- }
- func readInput(file string) []move {
- var moves []move
- content, err := ioutil.ReadFile(file)
- if err != nil {
- log.Fatal(err)
- }
- lines := strings.Split(string(content), "\n")
- for _, line := range lines {
- if line == "" {
- continue
- }
- var currentMove move
- n, err := fmt.Sscanf(line, "%s %d", ¤tMove.direction, ¤tMove.steps)
- if err != nil {
- log.Fatal(err)
- }
- if n != 2 {
- continue
- }
- moves = append(moves, currentMove)
- }
- return moves
- }
- func main() {
- if len(os.Args) < 2 {
- log.Fatal("No input file specified")
- }
- moves := readInput(os.Args[1])
- fmt.Println(moves)
- }
|