9 #define ROWS 29 // cheat by pre-inspecting input file
11 typedef struct node node
;
17 node grid
[ROWS
][COLS
];
20 move(int x1
, int y1
, int x2
, int y2
)
22 printf ("moving data from %d-%d to %d-%d\n", x2
, y2
, x1
, y1
);
23 grid
[y1
][x1
].used
+= grid
[y2
][x2
].used
;
24 assert (grid
[y1
][x1
].used
<= grid
[y1
][x1
].size
);
25 grid
[y1
][x1
].avail
-= grid
[y2
][x2
].used
;
26 grid
[y2
][x2
].avail
+= grid
[y2
][x2
].avail
;
27 grid
[y2
][x2
].used
= 0;
30 int main(int argc
, char **argv
)
35 int maxx
= 0, maxy
= 0;
36 while ((nread
= getline(&line
, &len
, stdin
)) >= 0) {
40 if (sscanf (line
, "/dev/grid/node-x%d-y%d %dT %dT %dT", &x
, &y
, &s
, &u
,
51 printf ("parsed %d columns over %d rows, for %d out of %d grid spots\n",
52 maxx
, maxy
, maxx
* maxy
, ROWS
* COLS
);
53 int startx
= -1, starty
= -1;
56 for (y
= 0; y
< maxy
; y
++)
57 for (x
= 0; x
< maxx
; x
++)
58 for (int i
= 0; i
< maxy
; i
++)
59 for (int j
= 0; j
< maxx
; j
++) {
64 if (grid
[y
][x
].used
< grid
[i
][j
].avail
) {
72 printf ("found %d viable pairs, all leading to %d-%d\n", viable
,
77 // I really don't feel like coding up an exploratory forking algorithm;
78 // pre-inspecting the data shows a brick wall from 24-9 through 34-9.
79 // Route around it by getting x to 23 before moving y to 0
82 move (x
, y
, x
- 1, y
);
87 move (x
, y
, x
, y
- 1);
90 while (x
< maxx
- 1) {
92 move (x
, y
, x
+ 1, y
);
97 move (x
, y
, x
, y
+ 1);
99 move (x
, y
, x
- 1, y
);
101 move (x
, y
, x
- 1, y
);
103 move (x
, y
, x
, y
- 1);
105 move (x
, y
, x
+ 1, y
);
108 printf ("total steps: %d\n", steps
);