-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestrot.go
59 lines (49 loc) · 1.41 KB
/
testrot.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
53
54
55
56
57
58
59
package main
import (
"fmt"
"reflect"
"array-rotation-algorithms/rotations"
)
type RotFunc func([]string, int) int
type RotateFunc struct {
fn func([]string, int) int
name string
}
var rotationfunctions = []RotateFunc{
{fn: rotations.Cyclic, name: "Cyclic "},
{fn: rotations.Reversal, name: "Reversal"},
{fn: rotations.Rotate, name: "Rotate "},
}
func main() {
orig := []string{
`a`, `b`, `c`, `d`, `e`, `f`, `g`, `h`, `i`, `j`, `k`, `l`, `m`,
`n`, `o`, `p`, `q`, `r`, `s`, `t`, `u`, `v`, `w`, `x`, `y`, `z`,
`A`, `B`, `C`, `D`, `E`, `F`, `G`, `H`, `I`, `J`, `K`, `L`, `M`,
`N`, `O`, `P`, `Q`, `R`, `S`, `T`, `U`, `V`, `W`, `X`, `Y`, `Z`,
`1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `0`, `~`, `!`, `@`,
`#`, `$`, `%`, `^`, `&`, `*`, `(`, `)`, `_`, `-`, `+`, `=`, `{`,
`[`, `}`, `]`, `|`, `:`, `;`, `"`, `'`, `<`, `,`, `>`, `.`, `?`,
`/`,
}
for L := 2; L < len(orig); L++ {
for N := 1; N < L; N++ {
std := make([]string, L)
copy(std, orig)
rotations.Slowrotate(std, N)
// std is the correct rotation, I hope
for _, rfn := range rotationfunctions {
array := make([]string, L)
copy(array, orig)
rfn.fn(array, N)
if reflect.DeepEqual(std, array) {
fmt.Printf("%s worked %2d -> %2d\n", rfn.name, L, N)
} else {
fmt.Printf("%s failed %2d -> %2d\n", rfn.name, L, N)
fmt.Printf("%v\n", std)
fmt.Printf("%v\n", array)
return
}
}
}
}
}