5 kyu

3-2-1 Fire!

Description
Loading description...
Games
Algorithms
  • Please sign in or sign up to leave a comment.
  • mauro-1 Avatar

    The (0, 0) is at the top left corner and the coordinates are (row, column).

    Why? There aren't coordinates in the interface of the function.

  • a5zima Avatar

    m = [ 'AvB', '>E<', 'C^D' ]

    test_case(m, ['A', 'B', 'C', 'D', 'E'])
    

    Maybe "E" must be hit 4 times here?

    • Blind4Basics Avatar

      you don't care about the number of hits. Just the targets that have been hit.

    • a5zima Avatar

      Are you sure? Because there are many tests with double strike like this:

      +------+ | C | |v A A| | | |\ <| +------+ ['A', 'C'] should equal ['A', 'A', 'C']

    • B1ts Avatar

      They're different objects, but they can have the same ID.

    • a5zima Avatar

      +----------+ |>A B<| | / D | | D B | => All enemies are defeated: ['A', 'B', 'B', 'D', 'D'] (Notice the repeated enemies) | | |\ < > /| +----------+

    • B1ts Avatar

      And there's 2 Bs and Ds on the map, and they're both hit, so it's all correct.

    • a5zima Avatar

      You are right! Thank you!

    • Blind4Basics Avatar

      mmh, I forgot about that subtlety. You didn't pay enough attention to this requirement:

      You only count each defeated enemy once, even if it is hit by more than one laser.

      (edit: seems I'm a little late... x) )

  • CodeUnicorn Avatar

    I think this kata also should have a tag 'game' since It's game-ish and fun

  • B1ts Avatar

    Apologies if dumb question, but I don't see where it's explained. Say we got a sample test:

    A>   \
    >    /
    CB     
    

    So then the top battleship shoots:

    A>---\
    >----/
    CB    
    

    How do I know whether the other spaceship below gonna reflect up or down? Can they shoot many times, and I have to check both options? I don't really see that info in description.

    • G_kuldeep Avatar

      you have to try each laser one by one.

      How do I know whether the other spaceship below gonna reflect up or down

      it will reflect both ways

      Can they shoot many times

      only one time but it will expand as it catches front of other laser

      I have to check both options?

      yes

    • Blind4Basics Avatar

      they do both systematically

    • B1ts Avatar
      Question marked resolved by B1ts 5 years ago
  • Blind4Basics Avatar

    you should add those 2 fixed tests: I bet a lot of implementation could fail them (surely they show up in the random tests, but it's better to have them in the fixed ones):

    lst = [''' A 
    > <
       
       
       
     ^ '''.split('\n'),
     ''' v 
       
       
       
    > <
     A '''.split('\n'),
     ]
    
  • Blind4Basics Avatar

    still not good:

    +-----------+
    |  3        |
    |        54 |
    | 0 v 6 74 4|
    |      9   0|
    |        >  |
    |   9   < 1 |
    |5  <\<  1  |
    | 7      1  |
    |   v   0>  |
    |7      ^ 3 |
    |    6v /   |
    +-----------+
    [0, 5, 9] should equal [0, 5, 7, 9]
    

    Note: what about using chars instead of numbers? (in the output) (I just saw your answer)

    EDIT: about the chars, if they are all unique, you can go back to a set as output x)

  • Blind4Basics Avatar

    Ok, that's not an edge case missing, that's a problem in your solution: seem like your lasers are trversing the ships:

    +-----------+
    |           |
    |    42 5   |
    |   ^  6    |
    |    7      |
    |2  /v  \ v |
    |           |
    |2  v^      |
    | \   \    v|
    | 0         |
    |   >    4  |
    |  3  ^     |
    +-----------+
    {4} should equal {4, 7}
    
  • Blind4Basics Avatar

    Hi,

    Seems a nice one, once again!

    There is a problem with the kind of output, tho: it should be a sorted list (or a list that you sort during the tests), not a set, especially if there can be multiple identical numbers. Asking for a set is opening the door to incomplete solutions to pass the tests.

    cheers

    EDIT: x) hummmm... I see why you did that, now. x) But it really should be a list ;p

    • Blind4Basics Avatar

      in addition, that would really ease the debugging, because... this...:

      +---------------+
      |  3  \     ^   |
      |5/3        0   |
      |      19       |
      |     8  /8 2v  |
      |   /           |
      |  7     8v\>   |
      |    4         9|
      |     2 / / 0   |
      |\         / 5  |
      | /9       > ^  |
      |9 8 38         |
      |               |
      |\ 8>           |
      |v  >^       /  |
      |             v |
      +---------------+
      {2, 3, 4, 5, 8} should equal {2, 3, 4, 5, 8, 9}
      

      is a nightmare... x)

      notes:

      1. your fixed tests are missing some kind of edge case. Dunno yet what it is
      2. seeing the size of the inputs/numbers: don't ask for integers, but for chars. This way you can us digits and lower/uppercase letters for the ennemies
    • Dr Gabo Avatar

      It should be fixed now (with sorted lists)!

    • Dr Gabo Avatar

      (Forgot to close)

      Edit: the chars are a good idea, I'll implement it.

      Issue marked resolved by Dr Gabo 5 years ago
    • Dr Gabo Avatar

      Now enemies are uppercase letters and the tests are a little bit easier to follow (in the end, they are random :S). You may want to modify your solution.