Thread: Wonka Factory Password

  1. #46
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    241
    This is fairly difficult, i feel that they meticulously made it tough lol. Some of the problems that arose seem intentional.

    Wonka Factory Password-pattern2-jpg

    like a boss...
    Attached Images Attached Images Wonka Factory Password-pattern-jpg 
    Last edited by Structure; 01-10-2020 at 11:00 AM.
    "without goto we would be wtf'd"

  2. #47
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    241
    Wonka Factory Password-pattern-png
    Attached Images Attached Images Wonka Factory Password-meme-jpg 
    Last edited by Structure; 01-10-2020 at 11:48 AM.
    "without goto we would be wtf'd"

  3. #48
    Registered User
    Join Date
    Aug 2019
    Location
    Inside a Singularity
    Posts
    258
    Yep, I linked the book from the Amazon website in my post which says the latest delivery is by Tuesday but I didn't order it from Amazon lol Found another website that was delivering within 24 hours and so placed the order on there . It's arrived now and I'm going to start reading it tonight. And really, I found it good just by looking at the reviews and Wiki, and I think it'll be a good adventure reading it. Thanks.

    Also, thanks to everyone who participated in this discussion. Really nice ideas have emerged (the linear solution by Hodor!) out of this discussion and have opened different ways for me to think in while solving problems.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook, The Wizardry Compiled

  4. #49
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    241
    working on the formula...
    Last edited by Structure; 01-14-2020 at 03:04 PM.
    "without goto we would be wtf'd"

  5. #50
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    241
    Code:
    if (time > 86) passWord = (((time-86)*20)+1094);
    Last edited by Structure; 01-14-2020 at 03:39 PM.
    "without goto we would be wtf'd"

  6. #51
    Registered User
    Join Date
    Aug 2019
    Location
    Inside a Singularity
    Posts
    258
    That would work only for a specific test case, not all possible cases. If this formula was meant for the original test sample, your equation is wrong. Test it out yourself

    What was the sample test you used which led you to this formula?
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook, The Wizardry Compiled

  7. #52
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    241
    It is correct. Perhaps you are using it wrong?

    The initial input is stated in the problem.
    Last edited by Structure; 01-15-2020 at 09:56 AM.

  8. #53
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    241
    For the first 86 you have to use your algorithm to get the correct passwords.
    The pattern starts at 86... for any time over 86:
    Code:
    passWord = (((time-86)*20)+1094)
    This is a "shortcut".

    time: 1001 = 19394
    time: 50000000000 = 999999999374



    as far as correct goes, every password at time, and strings displayed in the problem are 100% accurate.

    your equation is wrong
    Wonka Factory Password-mirror-jpg
    Last edited by Structure; 01-15-2020 at 10:13 AM.
    "without goto we would be wtf'd"

  9. #54
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    241
    If the algorithm is working correctly it should look like this...

    initial state: ....#..#.#..##......###...###....

    TIME: PASSWORD STRING
    001: 091 ....#...#....#.....#..#..#..#..................
    002: 132 ....##..##...##....#..#..#..##................
    003: 102 ...#.#...#..#.#....#..#..#...#................
    004: 154 ....#.#..#...#.#...#..#..##..##...............
    005: 115 .....#...##...#.#..#..#...#...#...............
    006: 174 .....##.#.#....#...#..##..##..##..............
    007: 126 ....#..###.#...##..#...#...#...#..............
    008: 213 ....#....##.#.#.#..##..##..##..##.............
    009: 138 ....##..#..#####....#...#...#...#.............
    010: 213 ...#.#..#...#.##....##..##..##..##............
    011: 136 ....#...##...#.#...#.#...#...#...#............
    012: 218 ....##.#.#....#.#...#.#..##..##..##...........
    013: 133 ...#..###.#....#.#...#....#...#...#...........
    014: 235 ...#....##.#....#.#..##...##..##..##..........
    015: 149 ...##..#..#.#....#....#..#.#...#...#..........
    016: 226 ..#.#..#...#.#...##...#...#.#..##..##.........
    017: 170 ...#...##...#.#.#.#...##...#....#...#.........
    018: 280 ...##.#.#....#####.#.#.#...##...##..##........
    019: 287 ..#..###.#..#.#.#######.#.#.#..#.#...#........
    020: 325 ..#....##....#####...#######....#.#..##.......

    verified by: http://www.hpcodewars.org/past/cw22/...ProblemSet.pdf
    Last edited by Structure; 01-15-2020 at 11:37 AM.
    "without goto we would be wtf'd"

  10. #55
    Registered User
    Join Date
    Aug 2019
    Location
    Inside a Singularity
    Posts
    258
    Oh yes, my bad. Sorry about that. I subtracted 84 instead of 86 which led me to think that the equation was wrong. Well done
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook, The Wizardry Compiled

  11. #56
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    241
    Quote Originally Posted by Zeus_ View Post
    Well done
    Thank You. Being polite goes a long way.

    How i solved this problem...
    Code:
    #include <stdio.h>
    #include <string.h>
    
    #define bit 4
    
    char *buffer;
    char sit = '.', stand = '#';
    char *initPattern = "#..#.#..##......###...###";
    double time = 0.0;
    char *mask = "...##..#...#....#.#..#.##.##...#####.#.##.#####.#.##.#####..###.#####.";
    int mask_bits[14], places[128];
    
    char toMatch[1024];
    
    int addDots = 0;
    
    char new_string[1024], string_buffer[1024];
    
    int starter = 0;
    double currentIndex;
    
    double setString(char *string) {
        int counter = 0, last = 0;
        double passValue = 0;
        int isReading = 0, bit_count = 0;
        memset(string_buffer,0,strlen(string_buffer));
        
        while (counter < strlen(string)) {
            if (string[counter] == '#') {
                last = (counter+1);
                if (starter == 0) {
                    starter = counter;
                    if (counter == 0) strcat(string_buffer,"...");
                };
                passValue = (passValue + (counter));
            };
            counter++;
            addDots = (counter-last);
        };
    
        if ((bit-starter) > 0) {
            if (currentIndex == 1) {
                for (int i=0;i<(bit-starter);i++) {
                    strcat(string_buffer,".");
                };
            };
        };
        strcat(string_buffer,string);
        return passValue;
    };
    
    void doDots() { 
        for (int i=0;i<(bit-addDots);i++) strcat(string_buffer,".");
    };
    
    float cull(char *string,int count) {
        int kickValue = 0;
        for (int x=0;x<5;x++) {
            if (string[count-x] == '#') {
              if (x == 0) kickValue += 1;
              if (x == 1) kickValue += 2;
              if (x == 2) kickValue += 4;
              if (x == 3) kickValue += 8;
              if (x == 4) kickValue += 16;
            };
        };
        return kickValue;
    };
    
    void patternLock(char *string) {
        int counter = 0, startRead = 0;
        int readCount = 0; 
        memset(toMatch,0,sizeof(toMatch));
        while (counter < strlen(string)) {
            if (counter == 4) startRead = 1;
            if (startRead == 1) {
                toMatch[counter-starter] = cull(string,counter-1);
                readCount += 1;          
            };
            counter++;
        };
    };
    
    void validMatches() {
        int ii = 0, ix = 0;
        for (int i=0;i<strlen(mask);i++) { ii++;
            if (ii == 5) { ii = 0; 
                mask_bits[ix] = (int)cull(mask,i);
                ix++;
            };
        };
    };
    
    double retrieve(char *string) {
        double x = setString(string); 
        return x;
    };
    
    void incorpPlaces() {
       memset(places,0,sizeof(places));
       for (int b=0;b<sizeof(toMatch);b++) {
            for (int c=0;c<(sizeof(mask_bits)/sizeof(int));c++) {
                if ((mask_bits[c] == toMatch[b]) && (toMatch[b] != 0) ) {
                    places[b] = mask_bits[c];
                };
            };
        };
    };
    
    void displayResult(int id) {
        if (id < 100) printf("0");
        if (id < 10) printf("0");
        printf("%i: ",id);
        int passCode = 0;
        memset(new_string,0,strlen(new_string));
        for (int i=0;i<(128);i++) {
            if (places[i] != 0) {
                strcat(new_string,"#");
                passCode += i-4;
            } else {
                strcat(new_string,".");
            };
        };
        
        printf("%i_",passCode);  
        printf("%s\n",new_string);
    };
    
    int main(int args, char *argv[]) {
    
        int maxGen = 100;
    
        validMatches();
    
        currentIndex = 1;
        retrieve(initPattern); doDots();
        printf("\n000: %s\n",string_buffer);    
        patternLock(string_buffer);
        incorpPlaces();
        displayResult(currentIndex);
    
        for (int lot=2;lot<=maxGen;lot++) {
            currentIndex = lot;
            retrieve(new_string);
            patternLock(string_buffer);
            incorpPlaces();
            displayResult(currentIndex);
        };
    
        return 0;
    };
    Last edited by Structure; 01-16-2020 at 02:07 PM.
    "without goto we would be wtf'd"

  12. #57
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,743
    Quote Originally Posted by Structure View Post
    Thank You. Being polite goes a long way.

    How i solved this problem...
    That only solves the simple where: a) the cycle length is 1; and b) the cycle repeats. It doesn't deal with input like

    Code:
    initial state ".#."
    patterns
    "....#"
    "#...."
    Which makes a much prettier dance:

    Wonka Factory Password-untitled-1-jpg

    But much more difficult to solve

    Edit: I wish I still had my code now. Anyway, The Nature of Code section 7.2. Look familiar? Now, there's probably a way to work calculate generation t for this particular case, like it's possible for the ones that end up being linear or semi-linear (cycling) but then how many other special cases are there and what if we get a random (see section 7.5 Wolfram Classification) one? I'm just going with what I said originally and considering this solved for cases where the pattern repeats in cycles of length=1 (i.e. the password being linear and the state being a "class 1" Wolfram class) (Cellular automaton - Wikipedia)
    Last edited by Hodor; 01-16-2020 at 10:05 PM.

  13. #58
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,743
    Some interesting reading as well (second link). In the second link scroll down to look at the graphs and read the discussion. Also worth reading is the section called "how hard are the problems? which is right at the bottom of the second link

    Wolfram Rule 30 Prizes
    Announcing the Rule 30 Prizes—Stephen Wolfram Writings

    Last edited by Hodor; 01-16-2020 at 10:29 PM.

  14. #59
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    241

    Thumbs up

    Look familiar?
    yep...
    initial state ".#."
    patterns
    "....#"
    "#...."
    I had to alter the code a little bit:
    Wonka Factory Password-pattern-jpg
    interesting...
    Last edited by Structure; 01-17-2020 at 10:07 AM.
    "without goto we would be wtf'd"

  15. #60
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    241
    much more difficult to solve
    understatement.
    "without goto we would be wtf'd"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 06-29-2014, 02:08 AM
  2. Replies: 2
    Last Post: 01-07-2009, 10:35 AM
  3. Question about the Factory pattern.
    By h3ro in forum C++ Programming
    Replies: 14
    Last Post: 11-27-2008, 04:55 PM
  4. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 01:41 PM
  5. Abstract Factory in C++
    By agrsaurabh in forum C++ Programming
    Replies: 1
    Last Post: 10-06-2003, 02:16 PM

Tags for this Thread