-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday21.go
More file actions
74 lines (61 loc) · 1.07 KB
/
day21.go
File metadata and controls
74 lines (61 loc) · 1.07 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
69
70
71
72
73
74
package main
import (
"fmt"
// "flag"
)
// Main routine
func runProgram(reg0Val int, maxLoop int) (int, int) {
var reg0, reg2, reg3, reg4, reg5 int = 0, 0, 0, 0, 0
var loopCounter int = 0
reg0 = reg0Val
reg5 = 0
goto6:
reg2 = (reg5 | 65536)
reg5 = 7571367
goto8:
loopCounter++
reg4 = (reg2 & 255)
reg5 += reg4
reg5 = (reg5 & 16777215)
reg5 = reg5 * 65899
reg5 = (reg5 & 16777215)
if 256 > reg2 {
goto goto28
}
reg4 = 0
goto18:
reg3 = reg4 + 1
reg3 = reg3 * 256
if reg3 > reg2 {
goto goto26
}
reg4++
goto goto18
goto26:
reg2 = reg4
goto goto8
goto28:
if loopCounter > maxLoop {
return 0, 0
}
if reg5 == reg0 {
return reg0, loopCounter
} else {
goto goto6
}
}
// Main routine
func main() {
var maxLoop = 2000
for tryIt := 0; tryIt < 100000000; tryIt++ {
result, loopResult := runProgram(tryIt, maxLoop)
if result != 0 {
fmt.Println("Result worked:", result, loopResult, maxLoop)
if maxLoop > loopResult {
maxLoop = loopResult + 1
}
} else {
//fmt.Println("Failed:", tryIt)
}
}
}