-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain2.go
56 lines (46 loc) · 1020 Bytes
/
main2.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
package main
import (
"fmt"
"strconv"
"strings"
)
var input = []byte("fbgdceah")
func main() {
str := input
lines := parse()
for i := len(lines) - 1; i >= 0; i-- {
line := lines[i]
ff := strings.Fields(line)
switch ff[0] {
case "swap":
if ff[1] == "position" {
x, _ := strconv.Atoi(ff[2])
y, _ := strconv.Atoi(ff[5])
str = InverseSwapPosition(str, x, y)
} else {
str = InverseSwapLetters(str, []byte(ff[2])[0], []byte(ff[5])[0])
}
case "rotate":
if ff[1] == "based" {
x := []byte(ff[6])
str = InverseRotateBasedOnLetter(str, x[0])
} else {
x, _ := strconv.Atoi(ff[2])
if ff[1] == "left" {
str = InverseRotateLeft(str, x)
} else {
str = InverseRotateLeft(str, -x)
}
}
case "reverse":
x, _ := strconv.Atoi(ff[2])
y, _ := strconv.Atoi(ff[4])
str = InverseReverse(str, x, y)
case "move":
x, _ := strconv.Atoi(ff[2])
y, _ := strconv.Atoi(ff[5])
str = InverseMove(str, x, y)
}
}
fmt.Println(string(str))
}