|
@@ -54,6 +54,16 @@ func parseBoxes(line string, boxes [][]byte) [][]byte {
|
|
return boxes
|
|
return boxes
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func parseMove(line string) move {
|
|
|
|
+ var current move
|
|
|
|
+ n, err := fmt.Sscanf(line, "move %d from %d to %d", ¤t.what, ¤t.from, ¤t.to)
|
|
|
|
+ if n != 3 || err != nil {
|
|
|
|
+ log.Fatal("Can't parse move!", err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return current
|
|
|
|
+}
|
|
|
|
+
|
|
func readInput(file *os.File) ([][]byte, []move) {
|
|
func readInput(file *os.File) ([][]byte, []move) {
|
|
scanner := bufio.NewScanner(file)
|
|
scanner := bufio.NewScanner(file)
|
|
var moves []move
|
|
var moves []move
|
|
@@ -71,6 +81,8 @@ func readInput(file *os.File) ([][]byte, []move) {
|
|
boxes = parseBoxes(line, boxes)
|
|
boxes = parseBoxes(line, boxes)
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ moves = append(moves, parseMove(line))
|
|
}
|
|
}
|
|
|
|
|
|
return boxes, moves
|
|
return boxes, moves
|
|
@@ -88,6 +100,6 @@ func main() {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- boxes, _ := readInput(file)
|
|
|
|
- fmt.Println(boxes)
|
|
|
|
|
|
+ boxes, moves := readInput(file)
|
|
|
|
+ fmt.Println(boxes, moves)
|
|
}
|
|
}
|