Thread: Wonka Factory Password

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Quote Originally Posted by Zeus_ View Post
    I found a solution to the problem in Python, although I don't understand the language much and find it weird. I feel that my choice of C/C++ at school was a good decision.
    This works, but I don't see what makes it fast. Will try converting code to C++ and try understanding it while doing so. Will hopefully learn a bit of Python too.

    Code:
    
    

    That does exactly the same as my solution and uses a linear formula once a cycle (repeat) is detected.

    It doesn't work for the more general case (e.g. john.c's example; just tested to confirm). I expect the problem cannot be solved in the more general case, because for (e.g.)

    Code:
    initial state: ##
    2
    64
    ....#
    #....
    0
    ... starting with this state and using those patterns 2 standing and 2 sitting oompahs will be added to the start and end of the state for each iteration and therefore a cycle cannot occur in the state.

    If that's an official solution then they only want the problem solved for special case inputs where the state does cycle and if that's the case I guess the problem is solved. They could have stated that in the problem description if that's the case though (something like "we will only give the program inputs that we know will lead to a cycle, your program may give up if a cycle is not detected less than t=100000") :/

  2. #2
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    That python solution solves the same two special cases where cycles occur the the sub-cycles are also linear (that's what the remainder stuff is for... same as mine y=mx+c to get to the start of the cycle and then same linear for the remainder the bit within the cycle.


    That works fine when the cycle is a simple "step" like this:

    Wonka Factory Password-capture-jpg

    where the bit between the cycles in linear as well but it fails when the bit between cycles is not linear.

    For example:
    Code:
    initial state: #..#.#..##......###...###
    105
    4140
    ...##
    ..#..
    .#...
    .#.##
    .##..
    .####
    #.#.#
    ###..
    0
    My code fails on that, and so does the Python code. But it does cycle (starting at t=45 to t=49). The graph for that input looks like below. Both my code and the python code work if 't' is evenly divisible by the cycle length (t2 - t1), but otherwise my code and the python code both fail even though there the pattern does cycle (the passwords in between the cycle length, the sub cycles, are not linear). I suspect that if that's the official answer they only want it to work in very limited situations (where the cycle and sub-cycle are both linear)

    Wonka Factory Password-capture-jpg
    Last edited by Hodor; 01-02-2020 at 11:43 PM.

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