6 kyu

van Eck sequences

34 of 36JohanWiltink
Description
Loading description...
Algorithms
  • Please sign in or sign up to leave a comment.
  • LegendaryFartMaster Avatar
  • LegendaryFartMaster Avatar

    It is not clear from the instruction if functions other that term will be called before the sequence has grown enough. For Example, given the Van Eck Series: 0, 0, 1, 0, 2, 0, 2, 2, 1, 6, ...

    Is this an expected test case?

    let ins = VanEck(0) // Initialize van eck starting at 0
    
    assert(ins.first(6) == 9) // Note that `term` is not called to let the sequence grow.
    

    The test cases seem to always have enough calls to .term to let the sequence grow, however, the description reads as if there is no specific order in which the functions will be called.

    My question is: I'm working on translation this to Scala. Should i have a test case as described above? If yes: Will the difficulty of the kata be different between Javascript and Scala? If no: Should the Kata description be updated to reflect this clarification?

    Or is it Secret Option no C: I'm blind and the original JS kata does infact test for such "out-of-order" calls?

    Thanks for reading all that!

    • JohanWiltink Avatar

      The description does not specify any order for calling methods, and it's secret option C: the random tests will very probably generate tests where methods other than term will be called with arguments that have not been generated by term. Note that the reference solution solves this by explicitly calling term before accessing the other methods.

      It would be possible to add a fixed test that addressed this hypothetical vulnerability, but it hardly seems worth it.

      Does this answer your question?

    • LegendaryFartMaster Avatar

      Yes it did! I did assume that the random test does not guarantee the order of funtion calls. I am thinking of adding this as a fixed and random test, just so that it is explicitly checked every time. It's pretty straight forward the way im writing unit tests, and ensures that this behaviour is captured

      Hope that doesn't violate any translation rules!

      Question marked resolved by LegendaryFartMaster 4 years ago
  • Luvexina Avatar

    When I saw the "Don't Know"s, I instanly thought Numberphile

  • anter69 Avatar

    Any python/ruby translation forseen?

    • JohanWiltink Avatar

      Not by me; I only speak JavaScript and Haskell. You're welcome to submit one ( yes please! ).

      Mind that you don't accidentally randomly generate a seed of multiple 1s only - strange things happen .. :P

    • anter69 Avatar

      Unfortunately, I don't know JS nor haskell yet, so I'll have to wait...

      Question marked resolved by anter69 6 years ago
  • B1ts Avatar

    After seeing how first 2 van Eck katas went, I didn't expect anyone to touch this sequence again :P It looks like the twists you added made it good enough, and hard enough. Well done!

    One minor issue I have is: why is the method to find max number called fast ? It has nothing to do with speed and it threw me off-guard :( Why not just call it max / maxSomething?

    • JohanWiltink Avatar

      "How fast does it grow?"

      I considered asking for the rate of growth, but that would have been a float ( well, a rational ).

  • JohanWiltink Avatar

    A Haskell translation may be forthcoming. Watch this space ..