Flatten the grid into a single string (separated by line-feeds to side-step wrap-around problems) and use the offset in the string to identify cells instead of (x, y) tuples. Don't calculate part one separately, just do it as we go.master
|
|
||
2 |
|
2 |
|
3 |
|
3 |
|
4 |
|
4 |
|
5 |
|
|
|
6 |
|
|
|
|
5 |
|
|
7 |
|
6 |
|
|
7 |
|
|
8 |
|
8 |
|
9 |
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
|
|
|
|
9 |
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
13 |
|
14 |
|