Ad
  • Custom User Avatar

    I added two examples of large values to the sample and fixed tests in all the translations.

  • Custom User Avatar

    Will do when I get a chance, probably Tuesday.

  • Custom User Avatar

    The condition "c to be less than int max" is really redundant, since all variables are ints.

    I did add the following text to the description, which hopefully will clarify things:

    Note: Although a, b, c are all integers, it's possible that their squares can exceed the integer bound in a statically-typed language. Such solutions should be included.

  • Custom User Avatar

    Hi eurydice5717,

    I believe I have fixed the issue. Please try again and let me know.

    Regards,

    brodiemark

  • Custom User Avatar

    can't verify due to not having solved in c++/not seeing your code
    but - this looks to me like you're mixing up different test cases, ie. you're showing the input of one test and the expected output of a different one. be careful with how you print and how you read the output.

  • Custom User Avatar

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

  • Custom User Avatar

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

  • Custom User Avatar
  • Custom User Avatar

    Does that edge case (n=1, k=10) still exist? Right now, the description says (0 ≤ k ≤ n^2).

  • Custom User Avatar

    in your quote you left out the key part:

    the rubber band increases in length from the right side

    It is perfectly conceivable that the left end of the rubber band is tied to something so that the rubber band is only stretched rightwards. Feel free to propose concrete suggestions to improve the wording

  • Custom User Avatar

    Yes you are right that you normally wouldn't change the input vector. I wanted to keep it as simple as possible with this one, that's why I didn't make it constant. But I will change it :)

  • Custom User Avatar

    Whatever you want.

    btw I didn't fix the part where it conditionally runs a test

    return s, expected # no change made?

    and this condition is also weird looking:

    if pieces and illegal_chars:

    because conceivably that could be satisfied 0 times and make no changes and still change the expected value to False. but maybe the data ensures that logic does happen. it's also shuffling multiple times even though once has the same effect, which adds to the feeling that .. something is off.

    Anyway I get that this is probably straight from cpp, including the giant if/else thing. Do whatever you want even if it's nothing. For my part I just need to fulfill my urge to point it out.

  • Custom User Avatar

    You can probably edit it and unpublish it yourself.

    Tried this, but it doesn't seem to have had any effect.

    Your refactoring looks good to me. Would you like me to incorporate it into my version, or do you want to publish a new Python translation?

  • Custom User Avatar

    You can probably edit it and unpublish it yourself.

    This part doesn't look right to me:

                        else:  # Replace one letter with another, invalidating the solution
                            pieces = get_letters(t)
                            if len(pieces) >= 2:
                                t = replace_with(t, pieces[0], pieces[1])
                                
                                if is_valid_solution(t) != False:
                                    test.expect(False, f"Batch {count + 1} failed for grid:\n{t}\nExpected: False, Got: {is_valid_solution(t)}")
                                    break
                                else: test.expect(True, f"Batch {count + 1} passed for grid:\n{t}\n")
    

    running a test here is.. conditional? so sometimes it won't be 2000 tests even though 2000 iterations are made? but I ran it a few times and didn't have it happen so.. does it happen very rarely, is it a bug, can it be rewritten to ensure it carries out a test?

    I thought the nested control structures were a bit much and started refactoring.. which is why I thought the above thing is weird.

    Also noticed that when a solution is wrong the solution gets called AGAIN instead of looking at the value that was returned:

    f"... Expected: False, Got: {is_valid_solution(ss)} <- called again`"
    

    This is what I have in my editor atm:

    @test.describe("2000 Random Tests")
    def random_tests():
    
        def random_transform(s: str, expected: bool):
            ## Applies a random sequence of transformations to a string.
            return_string = s
            transforms = list("VHTVHTVHTVHT")
            random.shuffle(transforms)  # Shuffle transformation order
            for c in transforms:  # Apply each transformation in the shuffled order
                if c == 'T': return_string = transpose(return_string)
                elif c == 'V': return_string = vflip(return_string)
                elif c == 'H': return_string = hflip(return_string)
            return return_string, expected
    
        def replace_a_letter(s: str, expected: bool):
            # Replace one letter with another, invalidating the solution
            pieces = get_letters(s)
            if len(pieces) >= 2:
                return replace_with(s, pieces[0], pieces[1]), False
            return s, expected  # no change made?
    
        def swap_random_letters(s: str, _expected: bool):
            pieces = list(get_letters(s))
            random.shuffle(pieces)
            for _ in range(random.choice([1, 3])):  # Perform 1 or 3 swaps
                if len(pieces) >= 2:  # is this guaranteed to happen at least once?
                    s = swap_str(s, pieces[-1], pieces[0])
                    pieces = pieces[1:-1]
            return s, False
    
        def introduce_illegal_characters(s: str, _expected: bool):
            pieces = list(get_letters(s))
            illegal_chars = list("ABC1DK*abxyzegh?")
            for _ in range(2):  # Replace existing with invalid characters least twice
                if pieces and illegal_chars:
                    random.shuffle(pieces)
                    random.shuffle(illegal_chars)
                    s = replace_with(s, pieces[-1], illegal_chars[-1])
                    pieces.pop()
                    illegal_chars.pop()
            return s, False
    
    
        for count in range(10): ## Tests batched with 200 per batch (or test pane can crash or behave very slow otherwise).
                                ## Each batch aborts at the first failed test.
            @test.it(f"Batch {count+1}: Random Test Cases {200*count+1} to {200*(count+1)}")
            def test_case():
                for _ in range(200):
                    strategy = random.choice([
                        random_transform,
                        random_transform,
                        replace_a_letter,
                        replace_a_letter,
                        swap_random_letters,
                        introduce_illegal_characters,
                    ])
                    basecase, base_answer = test_list[random.randint(50, len(test_list) - 1)] # Pick a random test case, excluding first 50
                    testcase, expected = strategy(basecase, base_answer)
                    actual = is_valid_solution(testcase)
                    is_ok = actual == expected
                    test.expect(is_ok, f"Batch {count + 1} failed for grid:\n{testcase}\nExpected: {expected}, Got: {actual!r}")
                    if not is_ok:
                        break
    
  • Custom User Avatar

    It's already at a high standard.

    I know. I don't translate for just anybody. :-)

    By the way, there is a pending Python translation from me in the translation window which should be rejected. I think it's a result of my fork yesterday when I got mysterious failure messages. Today I just edited the current approved translation and re-published it. That's the one that should be used, correct? The one that aborts the batch.

  • Loading more items...