-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
68 lines (53 loc) · 1.1 KB
/
main.go
File metadata and controls
68 lines (53 loc) · 1.1 KB
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
package main
import (
"encoding/csv"
"fmt"
"github.com/danvolchek/AdventOfCode/2019/9/optimized/2/vm"
"io"
"os"
"path"
"strconv"
"strings"
)
func parse(reader io.Reader) []int {
csvReader := csv.NewReader(reader)
items, err := csvReader.Read()
if err != nil {
panic(err)
}
ret := make([]int, len(items))
for i, item := range items {
val, err := strconv.Atoi(item)
if err != nil {
panic(err)
}
ret[i] = val
}
return ret
}
func runPrint(tape, input []int) {
v := vm.VM{
Tape: tape,
In: input,
Debug: false,
}
v.Run()
fmt.Println(v)
}
func main() {
runPrint(parse(strings.NewReader("104,1125899906842624,99")), []int{})
runPrint(parse(strings.NewReader("1102,34915192,34915192,7,4,7,99,0")), []int{})
runPrint(parse(strings.NewReader("109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99")), []int{})
input, err := os.Open(path.Join("2019", "9", "input.txt"))
if err != nil {
panic(err)
}
tape := parse(input)
runPrint(cp(tape), []int{1})
runPrint(cp(tape), []int{2})
}
func cp(t []int) []int {
ret := make([]int, len(t))
copy(ret, t)
return ret
}