/
main.go
52 lines (47 loc) · 957 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"fmt"
"log"
"github.com/juubisnake/mars-rover/pkg/runner"
)
// main is an example of how to use the mars-rover runner.
func main() {
// a typical example of running a single robot across a surface.
instructions := `
5 5
1 2 N
LMLMLMLMM
`
result, err := runner.Run(instructions)
if err != nil {
log.Fatalf("failed while running instructions: %v", err)
}
fmt.Println(result)
// a example of running a multiple rovers across a surface.
instructions = `
5 5
1 2 N
LMLMLMLMM
3 3 E
MMRMMRMRRM
`
result, err = runner.Run(instructions)
if err != nil {
log.Fatalf("failed while running instructions: %v", err)
}
fmt.Println(result)
// a example of outputting the first rovers resting place given
// the second rover fails.
instructions = `
5 5
1 2 N
LMLMLMLMM
3 3 E
MMRMMRMRRMMMMMMMMMM
`
result, err = runner.Run(instructions)
if err == nil {
log.Fatal("instruction should have failed")
}
fmt.Println(result)
}