9 // cheat by pre-inspecting: all values and bots between 0 and 255 exclusive
11 typedef struct bot bot
;
21 unsigned char out
[MAX
];
23 int main(int argc
, char **argv
)
30 while ((nread
= getline(&line
, &len
, stdin
)) >= 0) {
34 if (sscanf (line
, "value %d goes to bot %d\n", &v
, &b
) != 2)
44 if (sscanf (line
, "bot %d gives low to %c%*s %d and high to %c%*s %d\n",
45 &b0
, &t1
, &b1
, &t2
, &b2
) != 5)
48 bots
[b0
].out_lo
= true;
50 bots
[b0
].out_hi
= true;
55 printf ("%d inputs are sorted among %d bots\n", inputs
, tasks
);
60 printf (" iteration %d\n", iter
++);
62 for (int i
= 0; i
< MAX
; i
++)
63 if (!bots
[i
].done
&& bots
[i
].v1
&& bots
[i
].v2
) {
64 printf ("tracing bot %d, v1 %d, v2 %d, lo %d, hi %d\n",
65 i
, bots
[i
].v1
, bots
[i
].v2
, bots
[i
].lo
, bots
[i
].hi
);
66 bots
[i
].done
= change
= true;
67 if (bots
[i
].v1
> bots
[i
].v2
) {
68 unsigned char tmp
= bots
[i
].v1
;
69 bots
[i
].v1
= bots
[i
].v2
;
75 else if (bots
[bots
[i
].lo
].v1
)
76 l
= &bots
[bots
[i
].lo
].v2
;
78 l
= &bots
[bots
[i
].lo
].v1
;
81 else if (bots
[bots
[i
].hi
].v1
)
82 h
= &bots
[bots
[i
].hi
].v2
;
84 h
= &bots
[bots
[i
].hi
].v1
;
87 if (bots
[i
].v1
== 17 && bots
[i
].v2
== 61)
91 printf ("values 17 and 61 are compared by bot %d\n", goal
);
92 printf ("first three outputs have product %d\n", out
[0] * out
[1] * out
[2]);