-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprog21.c
91 lines (75 loc) · 1.67 KB
/
prog21.c
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <stdio.h>
#include "intcode.h"
int64_t intcode_prog[] = {
#include "inputs/input21"
};
void put_str(struct intcode_machine * m, char * s)
{
while (*s) PUT(m->inputs, *(s++));
PUT(m->inputs, '\n');
}
// @................
// #####.#.#...#####
// @
// #####...###..####
// ....@............
// #####.#.#.##.####
//
// #####.#.#@##.####
#define S(a, b) #a " " #b
#define NOT(a,b) put_str(m, "NOT " S(a, b))
#define OR(a,b) put_str(m, "OR " S(a, b))
#define AND(a,b) put_str(m, "AND " S(a, b))
int main(int argc, char * argv[])
{
struct intcode_machine * m;
m = NEW_INTCODE_MACHINE(intcode_prog, _I());
run_machine(m);
while (!EMPTY(m->outputs)) {
printf("%c", (char)GET(m->outputs));
}
// J = 1 if smth to land on!
// put_str(m, "NOT D J");
// put_str(m, "NOT J J");
//
// // T = 1
// put_str(m, "NOT D T");
// put_str(m, "OR D T");
//
// // IF ANY HOLE A-C SET T TO 0
// put_str(m, "AND A T");
// put_str(m, "AND B T");
// put_str(m, "AND C T");
//
// // IF ANY HOLE A-C SET T TO 1
// put_str(m, "NOT T T");
//
// put_str(m, "AND T J");
// HOLE AT C, JUMP if we can land
NOT(C, J);
AND(D, J);
// BUT WAIT. SKIP JUMP IF E AND H are holes
NOT(E, T); // T is 1 if E is hole
NOT(T, T); // T is 0 if E is hole
OR(H, T); //
AND(T, J);
// HOLE AT A, JUMP
NOT(A, T);
OR(T, J);
// HOLE AT B, JUMP IF we can land?
NOT(B, T);
AND(D, T);
OR(T, J);
put_str(m, "RUN");
printf("ret: %ld\n", run_machine(m));
printf("%d\n", m->outputs.write - m->outputs.read);
if (m->outputs.read - m->outputs.write == -1) {
while (!EMPTY(m->outputs)) {
printf("%ld", GET(m->outputs));
}
}
while (!EMPTY(m->outputs)) {
printf("%ld\n", GET(m->outputs));
}
return 0;
}