8 static int debug_level
= -1;
10 debug_raw(int level
, const char *fmt
, ...) {
13 debug_level
= atoi(getenv("DEBUG") ?: "0");
14 if (debug_level
>= level
) {
16 vfprintf(stderr
, fmt
, ap
);
20 #define debug(...) debug_raw(1, __VA_ARGS__)
24 static char grid
[MAXY
][MAXX
];
31 if (debug_level
< level
)
34 for (j
= 0; j
< y
; j
++) {
35 for (i
= 0; i
< x
; i
++)
36 putchar(" X-"[grid
[j
][i
] - '0']);
42 main(int argc
, char **argv
) {
43 int zero
= 0, one
= 0, two
= 0, min
, best
, count
= 0, page
, ch
;
47 memset(grid
, '2', sizeof grid
);
53 if (!(stdin
= freopen(argv
[1], "r", stdin
))) {
76 if (grid
[(count
/x
)%y
][count
%x
] == '2')
77 grid
[(count
/x
)%y
][count
%x
] = ch
;
78 if (!(count
++ % page
)) {
87 printf("read %d bytes, best page value %d\n", count
, best
);