-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
41 lines (32 loc) · 815 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
package main
import (
"fmt"
"os"
"time"
"github.com/sanderploegsma/advent-of-code/2019/go/utils"
)
func main() {
instructions, err := utils.ReadIntCode("input.txt")
if err != nil {
fmt.Printf("failed to read input: %v\n", err)
os.Exit(1)
}
start := time.Now()
result := RunWithInput(instructions, 1)
fmt.Printf("[PART 1] output: %d (took %s)\n", result, time.Since(start))
start = time.Now()
result = RunWithInput(instructions, 2)
fmt.Printf("[PART 2] output: %d (took %s)\n", result, time.Since(start))
}
func RunWithInput(instructions []int, input int) int {
in := make(chan int, 1)
out := make(chan int)
go utils.RunIntCode(in, out, instructions)
in <- input
close(in)
output := make([]int, 0)
for o := range out {
output = append(output, o)
}
return output[len(output)-1]
}