6 kyu

Asteroid Collision

Description
Loading description...
Algorithms
Arrays
Lists
  • Please sign in or sign up to leave a comment.
  • brodiemark Avatar

    Question: In the example ([-2, -1, 1, 2]) ➞ [-2, -1, 1, 2], why don't the -1 and 1 meet and destroy each other?

  • Mercy Madmask Avatar

    This comment has been hidden.

  • Blind4Basics Avatar

    would be good to have in the example/fixed tests:

    • empty array
    • a bunch of medium arrays, as in... "debuggable" ones (length 10-15, no more. Like 5-10 of them)
    • side note: you don't need to copy the input when yu pass it to the ref solution, if it's called before the user's solution
    • saudiGuy Avatar

      done.

      regarding last point: I think it is necessary to pass a copy. If I use:

      solution = sol(x)
      user = asteroid_collision(x)
      

      then, user can pass all random tests by just return None return asteroids.

      Suggestion marked resolved by saudiGuy 17 months ago
    • Blind4Basics Avatar

      no, in that case, he cannot. It could happen if the calls were:

      user = asteroid_collision(x)
      solution = sol(x)
      

      summary, either:

      solution = sol(x)
      user = asteroid_collision(x)
      

      or

      solution = sol(x[:])
      user = asteroid_collision(x)
      
    • saudiGuy Avatar

      try:

      solution = sol(x)
      user = asteroid_collision(x)
      

      and initial solution:

      def asteroid_collision(asteroids):
          return asteroids
      
    • Blind4Basics Avatar

      oh right, I forgot your solution is mutating the input (bad practice... ;) )

  • Blind4Basics Avatar

    hidden spec, or wrong reference solution. See below:

    A=[-35, -36, 7, 94, -53, -77, 34, -66, 23, 20, -60, -43, 62, -20, 8, 67, -55, 23, 40, 50, -60, -1, -41, -17, 94, -41, 60, -26, -28, -72, -18, 69, -38, -43, 12, 11, -49, 51, -51, -72, -40, -50, -55, 65, 61, 70, 65, 45, -49, 58, 73, 40, 54, 77, 95, 23, -1, -50, 36, -67, 6, 34, 57, 8, 45, -35, -87, -21, 46, 91, -76, 36, -53, 28, -17, -45, 39, -77, -7, 72, 29, -74, -42, -53, -38, 6, 73, -34, 12, 54, -87, 36, 75, -54, 16, -85, -84, -10, 89, -53, 71, 86, 47, 21, 31, 81, -32, -47, -67, 72, -8, 66, -67, -27, -42, -44, -98, 12, 1, 79, -87, -33, -49, -92, -32, 91, -62, 14, -47, 68, 39, -18, -82, -38, 55, 39, 65, 31, -11, -40, -92, 99, 28, 11, -40, 80, 61, -24, -32]
    
    print(A.index(7), A.index(-98))  # 2, 116
    
    actual:   [-35, -36, 7, -98, -87, -33, -49, -92, -32, -92, 99, 80, 61] 
    expected: [-35, -36, -98, -87, -33, -49, -92, -32, -92, 99, 80, 61]
    

    According to what I understand from the description, those two (7 and -98) should never cross => ?

  • Blind4Basics Avatar

    I think the ref solution is wrong:

    [..., -19, -48, 100, -6, -21, -8, -52, -23, -85, -1, 83, 11, -34, 86, 86, -79, 78, -14, 42, -69, 54, 0, 63, -94, 36, -54, 58, -73, 82, 29, -100, 97, 99, 99 ...]
    actual:   [..., -19, -48, 97, 99, 99, ...] 
    expected: [..., -19, -48, 100, 83, 86, 86, 78, 54, 0, -94, -54, -73, -100, 97, 99, 99, ...]
    

    the 100 vs -100: all asteroids in between should be destroyed, and those 2 as well, shouldn't they? (probably linked to the presence of the 0 in between?)

    btw: the random tests are printing stuff to the console.

  • Mercy Madmask Avatar

    Asteroids with a value of 0 are assumed to be moving right, this is not specified.