-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd19.go
64 lines (53 loc) · 1 KB
/
d19.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
package main
import (
. "./intcode"
"fmt"
"os"
)
func get(prog IntProg, i, j int) int {
in := make(chan int, 2)
out := make(chan int)
vm := &VM{prog.Clone(), Position(0), Position(0), Running, ChannelIO{in, out}}
go vm.Run()
in <- i
in <- j
return <-out
}
func main() {
prog := LoadIntProg(os.Args[1])
sum := 0
for j := 0; j < 50; j++ {
for i := 0; i < 50; i++ {
v := get(prog, i, j)
sum += v
// fmt.Print(map[int]string{0: ".", 1: "#"}[v])
}
// fmt.Println()
}
fmt.Println("Result1:", sum)
type Row struct{ a, b int }
j := 3
rows := make([]Row, 0)
rows = append(rows, Row{0, 0})
rows = append(rows, Row{0, 0})
rows = append(rows, Row{0, 0})
n := 100
for {
last := rows[len(rows)-1]
a := last.a
for get(prog, a, j) != 1 {
a += 1
}
b := a
for get(prog, b, j) != 0 {
b += 1
}
row := Row{a, b}
rows = append(rows, row)
if len(rows) >= n && row.b-row.a >= n && rows[j-n+1].b >= a+n {
fmt.Println("Result2:", 10000*row.a+j-n+1)
break
}
j += 1
}
}