Thread: Puzzle

  1. #1
    Registered User
    Join Date
    Dec 2017
    Posts
    1,644

    Puzzle

    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
    A six-sided die, with numbers (positive/negative integers) written on each of its faces, is placed on the 6-by-6 grid above, in the lower-left corner. It then makes a sequence of moves. Each move consists of tipping the die into an orthogonally adjacent square within the grid.

    We start with a score of 0. On the Nth move, the score increases by N times the value of the upper face of the die after the move. However, the die is only allowed to move into a square if the score after the move matches the value in the square. Also, the die cannot be translated or rotated in place in addition to these moves.

    After some number of moves the die arrives in the upper-right corner, which ends its journey.

    The answer to this puzzle is the sum of values in the unvisited squares.
    A little inaccuracy saves tons of explanation. - H.H. Munro

  2. #2
    Registered User
    Join Date
    Feb 2022
    Location
    Canada, PEI
    Posts
    103
    Just to verify the puzzle. We start in the lower left corner at 0 and then we(for example) move to the square above which would could be: The running total of 0 plus the dice face value of 5 multi by number of rolls 1. And we move right...
    0 + (0 * dice side value) = 0
    0 + (1 * 5) = 5
    5 + (2 * 9) = 23
    etc..
    Last edited by G4143; 12-25-2022 at 03:35 AM.

  3. #3
    Registered User
    Join Date
    Dec 2017
    Posts
    1,644
    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;
    }
    Last edited by john.c; 12-25-2022 at 12:51 PM.
    A little inaccuracy saves tons of explanation. - H.H. Munro

  4. #4
    Registered User
    Join Date
    Feb 2022
    Location
    Canada, PEI
    Posts
    103
    Quote Originally Posted by john.c View Post
    ...
    The original problem is at the following link, near or at the top called "Die Agony": Puzzles Archive :: Jane Street
    ...
    Jane Street! That's those OCaml boys! You can bet the puzzle is tricky.
    Last edited by G4143; 12-25-2022 at 02:30 PM.

  5. #5
    Registered User
    Join Date
    Sep 2020
    Posts
    425
    I might give it a crack... My approach - looking for a chain where the difference between two squares divides by one, then by two, the 3rd one by three... then see which one folds onto a cube.

  6. #6
    Registered User
    Join Date
    Dec 2017
    Posts
    1,644
    Quote Originally Posted by hamster_nz View Post
    I might give it a crack... My approach - looking for a chain where the difference between two squares divides by one, then by two, the 3rd one by three... then see which one folds onto a cube.
    I was thinking the same thing sans the cube folding.
    I was thinking that if there's only one possible path according to the turns factor then that would have to be the answer.
    So the values on the cube wouldn't even come into it except to verify the result.
    A little inaccuracy saves tons of explanation. - H.H. Munro

  7. #7
    Registered User
    Join Date
    Feb 2022
    Location
    Canada, PEI
    Posts
    103
    Quote Originally Posted by hamster_nz View Post
    I might give it a crack... My approach - looking for a chain where the difference between two squares divides by one, then by two, the 3rd one by three... then see which one folds onto a cube.
    If I try it, it'll be a brute force solution.

  8. #8
    Registered User
    Join Date
    Sep 2020
    Posts
    425
    I think I've got it... mostly pen & paper, and a few minutes in a spreadsheet to calculate the differences.

    Easiest way was to look for a pattern of differences that divide by a sequence of numbers and ignore the cube completely until verifying the solution.

    If correct, the answer has something to do with, Pope Honorius IV, to not give the actual answer away.
    Last edited by hamster_nz; 12-25-2022 at 07:23 PM.

  9. #9
    Registered User
    Join Date
    Dec 2017
    Posts
    1,644
    It seems I've got a different answer. I could PM you my answer and code (very rough code).
    A little inaccuracy saves tons of explanation. - H.H. Munro

  10. #10
    Registered User
    Join Date
    Sep 2020
    Posts
    425
    Quote Originally Posted by john.c View Post
    It seems I've got a different answer. I could PM you my answer and code (very rough code).
    Sure! PM me!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GUI for N puzzle
    By Ovidiu in forum C++ Programming
    Replies: 2
    Last Post: 12-27-2014, 10:25 AM
  2. N Puzzle
    By Ovidiu in forum C++ Programming
    Replies: 15
    Last Post: 11-30-2014, 09:09 AM
  3. 15 Puzzle
    By jamorg01 in forum C Programming
    Replies: 3
    Last Post: 10-04-2009, 01:42 AM
  4. C Puzzle -Need Help..
    By ganesh bala in forum C Programming
    Replies: 2
    Last Post: 02-12-2009, 07:54 AM
  5. Puzzle!!!
    By Barnzey in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 12-30-2005, 12:34 PM

Tags for this Thread