Ad
  • Custom User Avatar
  • Custom User Avatar

    Really enjoyed this kata!

  • Custom User Avatar

    Found it! \o/

    For future solvers, I found a collection of whitespace programs here. Compiling and tracing those helped me figure out what was going on.

  • Custom User Avatar

    Ack! I'm almost done except for "Testing conditional and unconditional jump functionality", tests 5 and 6:

    '3' should equal '321'
    '3' should equal '3210'
    

    I don't know what the actual tests are, but I'm able to write tests that should loop from 3 down to 1 or 0, and they pass:

    loop321 = bleach(
        ''.join([
            'ss', 'sttn',          # PUSH 3
            'nss', 'stssssttn'     # MARK "C"
            'sns',                 # DUPLICATE
            'tnst',                # OUTPUTN
            'ss', 'stn',           # PUSH 1
            'tsst',                # SUB
            'sns',                 # DUPL
            'nts', 'stssststn',    # IFZERO "E"
            'nsn', 'stssssttn',    # GOTO "C"
            'nss', 'stssststn',    # MARK "E"
            'snn',                 # DISCARD
            'nnn'
        ])
    )
    Test.assert_equals(whitespace(loop321),'321')
    loop3210 = bleach(
        ''.join([
            'ss', 'sttn',          # PUSH 3
            'nss', 'stssssttn'     # MARK "C"
            'sns',                 # DUPLICATE
            'tnst',                # OUTPUTN
            'ss', 'stn',           # PUSH 1
            'tsst',                # SUB
            'sns',                 # DUPL
            'ntt', 'stssststn',    # IFNEG "E"
            'nsn', 'stssssttn',    # GOTO "C"
            'nss', 'stssststn',    # MARK "E"
            'snn',                 # DISCARD
            'nnn'
        ])
    )
    Test.assert_equals(whitespace(loop3210),'3210')
    

    Any clues for how to diagnose this case further?

  • Custom User Avatar

    I tried to calc the 2n term directly from the cloused form formula but the numbers are too big for the standar float, and
    are too big too for a reasonable precision of the decimal module. I tested some numbers and the calculation get too long
    before getting the needed precision.

    So the best way is using int. I did a raw for for it. The interesting of this solution is the use of a generator that improve the readability a lot.

  • Custom User Avatar

    This was a lot of fun! I haven't written an interpreter in a long time. I found Ruslan Spivak's series of articles to be very helpful.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    I had trouble passing the exception raising test for an invalid rank. I kept catching it at the place it causes trouble and raising it up to the calling function, but that wouldn't satisfy the test suite. Instead, I had to manually check that the rank was valid within inc_progress.

    I think test.expect_error should be more tolerant and allow errors to be raised from anywhere in the call stack.

  • Custom User Avatar

    Nice job with the docstring

  • Custom User Avatar

    Wow, this kata took me from binary long division to DFAs to Arden's Theorem. It was very tempting to google for a solution but I'm glad I didn't.

  • Custom User Avatar

    This is O(n^2) in time isn't it? It requires computing all n+1 Fibonacci numbers. But given andreidemin's comment, you only need one Fibonacci number.

  • Custom User Avatar
  • Custom User Avatar

    The most clever would be to mathemtically find the equation for nth term in the sequence.

    Interesting idea. The general solution to this 3rd order linear difference equation is a
    linear combination of exponentials r^n, where r is a solution to x^3-x^2-x-1 = 0. There are
    three roots r, two of which are nonreal. To find the coefficients, a 3x3 system of linear
    equations needs to be solved.