-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrev.go
More file actions
43 lines (33 loc) · 690 Bytes
/
Copy pathrev.go
File metadata and controls
43 lines (33 loc) · 690 Bytes
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
package main
import (
"fmt"
"log"
"os"
"reflect"
"strconv"
"array-rotation-algorithms/rotations"
)
func main() {
k, err := strconv.Atoi(os.Args[1])
if err != nil {
log.Fatal(err)
}
var orig []string
for _, str := range os.Args[2:] {
orig = append(orig, str)
}
n := len(orig)
cpy := make([]string, n)
copy(cpy, orig)
rotations.Slowrotate(cpy, k)
array1 := make([]string, n)
copy(array1, orig)
swaps := rotations.Reversal(array1, k)
if reflect.DeepEqual(cpy, array1) {
fmt.Printf("Reversal worked %2d -> %2d, %d swaps\n", n, k, swaps)
} else {
fmt.Printf("Reversal failed %2d -> %2d\n", n, k)
fmt.Printf("%v\n", cpy)
fmt.Printf("%v\n", array1)
}
}