-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (40 loc) · 837 Bytes
/
main.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
package main
import (
"encoding/binary"
"log"
"os"
"github.com/mattgen88/go-synacor-challenge/virtualmachine"
)
func loadChallenge() []uint16 {
data, err := os.Open("challenge.bin")
if err != nil {
panic(err)
}
defer data.Close()
var memory []uint16
for {
var i uint16
readErr := binary.Read(data, binary.LittleEndian, &i)
if readErr != nil {
return memory
}
memory = append(memory, i)
}
}
func main() {
debugLog, err := os.OpenFile("debug.log", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755)
if err != nil {
panic(err)
}
defer debugLog.Close()
stateLog, err := os.OpenFile("state.json", os.O_RDWR|os.O_CREATE, 0755)
if err != nil {
panic(err)
}
defer stateLog.Close()
vm := virtualmachine.New(loadChallenge())
vm.DebugFD = debugLog
vm.StateFD = stateLog
vm.Start()
log.Println("Goodbye")
}