Yes, that's correct. And, just to make it totally obvious, the current score is always the value of the square we are on.
Also, you need to keep track of what values you needed to put onto the die in order to make the first part of the trip since eventually the die will start showing these values again as it tips its way around the matrix. So you need to treat the die as a proper 3D object and keep track of it's orientation as well as it's position.
E.g. (an interesting little route that gives a lot of 9's)
Code:
Dir Sc Turn Die
N 0 + 1 * 5 = 5
E 5 + 2 * 9 = 23
E 23 + 3 * -9 = -4
S -4 + 4 * 9 = 32
-----
| 9 |
-----------------
| 9 | 5 | | -9|
-----------------
| |
-----
I should also say that I just ran into this problem yesterday and have not solved it myself yet.
The original problem is at the following link, near or at the top called "Die Agony": Puzzles Archive :: Jane Street
It currently does not give a solution, but will probably give it in January.
I have changed the wording a little to try to make it a little clearer.
Here's some starter code to read and print the matrix. I wrote the read routine to be able to read the data from the top of the code file in a multiline comment.
Code:
/*
57 33 132 268 492 732
81 123 240 443 353 508
186 42 195 704 452 228
-7 2 357 452 317 395
5 23 -4 592 445 620
0 77 32 403 337 452
*/
#include <stdio.h>
#include <stdlib.h>
#define SIZE 6
void print(int g[][SIZE]) {
for (int r = 0; r < SIZE; ++r) {
for (int c = 0; c < SIZE; ++c)
printf("%3d ", g[r][c]);
printf("\n");
}
}
int read_puzzle(int g[][SIZE], const char *fn) {
FILE *f = fopen(fn, "r");
// skip lines until we find one starting with an integer
while (fscanf(f, "%d", &g[0][0]) != 1 && !feof(f))
while (fgetc(f) != '\n' && !feof(f)) ;
for (int r = 0; r < SIZE; ++r)
for (int c = 0; c < SIZE; ++c) {
if (r == 0 && c == 0) ++c;
if (fscanf(f, "%d", &g[r][c]) != 1) { fclose(f); return 0; }
}
fclose(f);
return 1;
}
int main() {
int g[SIZE][SIZE];
if (!read_puzzle(g, "puzzle.c")) { // read puzzle data from top of code file
printf("bad puzzle\n");
exit(1);
}
print(g);
return 0;
}