-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain1.go
83 lines (71 loc) · 1.13 KB
/
main1.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import "fmt"
func main() {
t := Turing{
Tape: make(map[int]bool),
Cursor: 0,
}
t.NextState = t.A
for i := 0; i < 12134527; i++ {
t.NextState()
}
count := 0
for _, v := range t.Tape {
if v {
count++
}
}
fmt.Println(count)
}
type Turing struct {
Tape map[int]bool
Cursor int
NextState func()
}
func (t *Turing) A() {
if !t.Tape[t.Cursor] {
t.state(true, 1, t.B)
} else {
t.state(false, -1, t.C)
}
}
func (t *Turing) B() {
if !t.Tape[t.Cursor] {
t.state(true, -1, t.A)
} else {
t.state(true, 1, t.C)
}
}
func (t *Turing) C() {
if !t.Tape[t.Cursor] {
t.state(true, 1, t.A)
} else {
t.state(false, -1, t.D)
}
}
func (t *Turing) D() {
if !t.Tape[t.Cursor] {
t.state(true, -1, t.E)
} else {
t.state(true, -1, t.C)
}
}
func (t *Turing) E() {
if !t.Tape[t.Cursor] {
t.state(true, 1, t.F)
} else {
t.state(true, 1, t.A)
}
}
func (t *Turing) F() {
if !t.Tape[t.Cursor] {
t.state(true, 1, t.A)
} else {
t.state(true, 1, t.E)
}
}
func (t *Turing) state(val bool, direction int, nextState func()) {
t.Tape[t.Cursor] = val
t.Cursor += direction
t.NextState = nextState
}