-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd21.go
71 lines (59 loc) · 1.09 KB
/
d21.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
package main
import (
. "./intcode"
"fmt"
"os"
)
func send(ch chan int, s string) {
for i := 0; i < len(s); i++ {
ch <- int(s[i])
}
ch <- 10
}
func main() {
prog := LoadIntProg(os.Args[1])
in := make(chan int, 1000)
out := make(chan int)
vm := &VM{prog.Clone(), Position(0), Position(0), Running, ChannelIO{in, out}}
go vm.Run()
send(in, "OR D J")
send(in, "NOT C T")
send(in, "AND T J")
send(in, "NOT A T")
send(in, "OR T J")
for i := 0; i < 10; i++ {
send(in, "OR J J")
}
send(in, "WALK")
for c := range out {
if c > 255 {
fmt.Println(c)
} else {
fmt.Print(string(c))
}
}
in = make(chan int, 1000)
out = make(chan int)
vm = &VM{prog.Clone(), Position(0), Position(0), Running, ChannelIO{in, out}}
go vm.Run()
send(in, "OR E J")
send(in, "OR H J")
send(in, "AND D J")
send(in, "NOT T T")
send(in, "AND A T")
send(in, "AND B T")
send(in, "AND C T")
send(in, "NOT T T")
send(in, "AND T J")
for i := 0; i < 6; i++ {
send(in, "OR J J")
}
send(in, "RUN")
for c := range out {
if c > 255 {
fmt.Println(c)
} else {
fmt.Print(string(c))
}
}
}