6 kyu

Count the photos!

666 of 1,381billgewrgoulas
Description
Loading description...
Algorithms
Performance
Arrays
  • Please sign in or sign up to leave a comment.
  • pavloslav Avatar
  • ahmet_popaj Avatar

    This one was so hard for being a yellow kata you have no idea, because it's all about dynamic programming and optimizing, so I'd rank it up, really funny, yet more complex than challenging.

  • Alexenon Avatar

    Very cool kata, thanks so much!

  • benjaminzwhite Avatar

    Language : C++

    There is a problem with 1 (and only 1) of the fixed tests in the Hidden Test Cases:

    Assert::That(countPhotos(".>><<>..>><>.<><<><<<>...<.<><.......>>><<>><>.>
    .<..<><<<.>.><.>.>.<>.><><..>.<>..>><>>.<<.<.>.<<><.>...<>..<>...<><.<<<')"), Equals(1748));
    
    // n.b. I split it over 2 lines to avoid formatting issues
    

    This test case ends with the chars ') - i.e. chars which are not > < or . - this was probably an accident while pasting the string from another language version where strings are terminated with '.

    I don't think it's deliberate/intended to be a test case for input validation (invalid chars) because such tests don't appear in the other language I have solved (Python) and isn't mentioned in Description.

  • suic Avatar

    This was fun. Thanks!

  • laurelis24 Avatar

    Almost timed out but did it... Nice kata.

  • fcr-- Avatar
  • cluod-Alfakhre Avatar

    This comment has been hidden.

  • Jelybene Avatar

    This comment has been hidden.

  • benjaminzwhite Avatar

    2 small issues with Python translation:

    1. function name should be in snake_case count_photos. Only 8 solutions in Python so far if you want to change this quickly.

    2. some of the fixed tests have invalid characters, presumably from copy-pasting:

    ("'..<..<>>>><..>>><..><>.<>><><>>.<>>.><<<<>.<><.>>.>..>..>>.>><>><.><>.<<>.<.<.<.'", 720) # <--- "' at start and end of string
    
    (".>><<>..>><>.<><<><<<>...<.<><.......>>><<>><>.>.<..<><<<.>.><.>.>.<>.><><..>.<>..>><>>.<<.<.>.<<><.>...<>..<>...<><.<<<')", 1748) # <----- ') at end of string
    

    I will past a copy of a link to this post in a reply to the Python translator @macambira

  • shinyclovers Avatar

    C++ translation, followed python random test case generation https://www.codewars.com/kumite/631bb49b585a390024989834

  • Dmillenaar Avatar

    My solution is proven to work and works quick in PyCharm but here it times out after 12 seconds with failed tests(?) Running the failed tests in PyCharm does not provide the same result as given here. Not quite sure how I could speed it up anymore or how to not make it fail tests that work fine in another IDE.

  • macambira Avatar
  • JohanWiltink Avatar

    This kumite shows that tests are too strict.

    That solution is strictly O(n), but iterates twice instead of once ( "O(2n)", which is O(n) ). But it times out -- unlike the solution it is based on, which iterates once.

    If you require O(n), the constant factor should, within reason, not matter. I don't think this approach is unreasonable. Use fewer, bigger, tests to test performance.

  • DanielSzimko Avatar

    This comment has been hidden.

  • zLuki Avatar

    @billgewrgoulas I'll approve as 6kyu. Is that ok for you?

  • zLuki Avatar

    This comment has been hidden.

  • Blind4Basics Avatar

    Hi,

    • Don't use string concatenation to build the random input, this slowes down significantly the random tests (nothing critical here, but still)

    Cheers