6 kyu

A different kind of 'Lazy' function.

Description
Loading description...
Decorator
  • Please sign in or sign up to leave a comment.
  • maestroviktorin Avatar

    An underrated kata, it should be more popular, as it really makes your brains move a little.

  • seniorCrutchDeveloper Avatar

    Keep it up, I demand more decorator tasks, really like your kata series)

  • JiPiBi Avatar

    Learned a lot about decorators and arguments passed to wrapper (Thanks to Google!) . Thanks to you too!

  • KepLer100500 Avatar

    My solution passed all tests (Passed: 307 / Failed: 4), except for the "Multiple lazy functions should work fine" block. Please tell me how it should look like?

  • vitorrafael Avatar

    Hello, I've been trying to pass the test cases however I'm facing some errors in the negative number situation.

    For the input with @lazy(-2) and i = 2 and j = 5 (that is the 5th call) it is saying that it should be None. However, the following calls passed:

    • 2 1 56
    • 2 2 None
    • 2 3 56
    • 2 4 None

    The next is the one that I described before, should it really be None? Since it the 1st call after a lazy call and n == -2

  • Hamburgler Avatar

    It's great to see a decorator show up. I would appreciate more problems with python-specific language features instead of algorithms to which any language can be applied.

  • Awesome A.D. Avatar

    Suggestion: Maybe explicitly describe the requirement that when a function is currently "lazy", it is not to be run at all. This only becomes clear when the solution is subtely wrong (i.e. calls the decorated func regardless of laziness and only then decides what to return) and the test catches it (by having the decorated func have a side effect but not return anything itself). Requirements that only become clear during testing are a pet peeve of mine :-) In this case it was relatively harmless, but in other cases can require that an otherwise logically sound and functioning approach must be rewritten from scratch, throwing hours of work out the window.

  • natan Avatar

    Should only increment when called

    Not sure what that code is trying to test. It creates two variables b and c, but assignment has nothing to do with lazy this does not fire off any sort of event. Likewise, looking up a local variable (_a) does not have any effect. b = _a There for overall does nothing. c = dir(_a) which should be dir(_a) does do something if _a happens to implement __dir__ but why would it ever? That's really really arbitrary. Can you show code that fails this test but passes the others? It is practically unfailable from what I can tell (aside from wrong answers but other tests cover that).

    something you could additionally test for is that the decorator is reusable, that is:

    a = lazy(3)
    @a
    f(): return 1
    @a
    g(): return 2
    

    f and g should not be sharing state. Idk, maybe nobody cares and maybe it's difficult to explain what went wrong in error output.

  • Blind4Basics Avatar

    could you please separate the 20 random tests wrapping them inside @test.it blocks?

  • FArekkusu Avatar

    Why for negative inputs the n-th, 2n-th, 3n-th etc. calls are lazy, but for positive inputs the 1-st, (n+1)-th, (2n+1)-th etc. calls are non-lazy?

  • Kacarott Avatar

    This is my first Kata so if I have accidentally made a duplicate, or if there's anything to improve please let me know!