Ad
  • Custom User Avatar
    [13035, 6618, 13056, 20912, 1119, 13035, 6618, 6618, 8482, 13056]  --> 10
    [13035, 6618, 13056, 20912,  x  , 13035, 6618, 6618, 8482, 13056]  --> 9
    [13035,   x , 13056, 20912,  x  , 13035,   x ,   x , 8482, 13056]  --> 6
    [13035,   x , 13056, 20912,  x  , 13035,   x ,   x ,   x , 13056]  --> 5
    [  x  ,   x , 13056, 20912,  x  ,   x  ,   x ,   x ,   x , 13056]  --> 3
    [  x  ,   x ,   x  , 20912,  x  ,   x  ,   x ,   x ,   x ,   x  ]  --> 1
    
  • Custom User Avatar

    As @St3f4n wrote above, I believe this is caused by @marcusaurelius's solution modifying the input list. JavaScript version works because the test gives a copy of generated array. I don't recommend modifying the input either, but to prevent further issues like this, I think it's better for the Python tests to also copy the generated list.


    Relevant parts of the current tests:

    random_strings = [gen_random_string(), gen_random_string()]
    user = tail_swap(random_strings)  # if `random_strings` get modified,
    answer = solution(random_strings) # reference solution will be given user's solution as an input
    test.assert_equals(user, answer)
    
    Test.assertDeepEquals(tailSwap(t.slice()), sol(t)); // not an issue in JavaScript test because of `t.slice()`
    

    edit: Just tried @marcusaurelius's solution from above and confirmed that it passes all tests if a new list is created and returned (without modifying input list)

  • Default User Avatar

    The tests are using the function that you wrote and no more.... if you import re outside of the function, it wouldn't get picked up when the function is called in the tests.

  • Custom User Avatar

    I'm not an expert in Python but I think the problem is that you are changing the input array with
    strings[0] = a

    strings[1] = b
    .
    In javascript the array was copied before given as input. Either way dont ever modify the input(always copy it if its an object or array/list) to the function, that can influence the testing. Hope that was helpfull.

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    okay so it looks like the submit solution button for python isn't calling the function, I just rewrote my solution so that it doesn't use the re module and it passes all test cases, but fails when I press "attempt". When I include the value that caused the failure in my test case list, my code passes - so something must be going wrong behind the scenes...

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    I run my code in Python on my local machine - and it works, I run the test cases and my solution works, I submit the code and it fails on cases that, when I test, my code suceeds on. This must be broken...

  • Custom User Avatar

    The testcases for python are correct, your solution must be wrong;-)...