Ad
  • Default User Avatar
    • Please do away with the using namespace std; it forces that style on users who don't want it.
    • The fixed tests should also be in the submission tests too.
    • Minor stylistic nitpick, but scoping every assert statement in the fixed tests is unneeded and might be a source of confusion.
    • The input sizes are determined at compile-time. This is not random
    • The usage of std::linear_congruential_engine here is overengineered; with this config, it generates a linear sequence with a step of 3 starting from 1 (exclusively). Every single test run would generate the sequence (4, 4+3, 4+3+3, ...) without fail. This is also not random
    • All the values in the generated b are from a. This doesn't test how the user's solution handles values in b that are not in a. Also, this means that b preserves the order of a which reduces the randomness further.
    • This point is more general, but I really feel like the structure of the random tests can be massively simplified. Between the usage of std::linear_congruential_engine, the need for explicit moves, the magic numbers (like LN/4) and the reaally long function, I really feel like some parts can be refactored, some removed, and some restructured to make the random testing strategy more readable.
  • Default User Avatar

    never thought I would see asm here

  • Custom User Avatar

    what in the absolute code is this

  • Custom User Avatar

    Please use spoiler flag next time. Because you did integer division there. That's how Ruby's division work.

  • Default User Avatar

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

  • Custom User Avatar

    devagya, please use spoiler flag next time.

  • Custom User Avatar

    It can be, but plenty of compilers will optimize a divide-by-two into a shift anyway. (Specifically any divide-by-power-of-two can be turned into a single shift)

  • Default User Avatar

    Yes, bit operating is faster

  • Default User Avatar

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

  • Custom User Avatar

    As guriyeller correctly observes, for all numbers greater than 1, multiplying will give the maximum result. So I special-cased where numbers are equal to 1, because then it's better to add them to another multiplier. For a and c that can only be to b, for b it depends on whether a<c or not; (a+1)c==ac+c and a(c+1)==ac+a. I made use of invariants throughout the various steps to arrive at a compact final expression, carefully avoiding overwriting values. All paths that add to variables make sure the correct variables are still 1 to not affect the result.

  • Default User Avatar

    i love your solution, you must be an Obfuscated C code contestant ;-)

  • Custom User Avatar
  • Custom User Avatar

    i was very surprised how few C solutions actually used #include <regex.h>
    given that it is tagged as a regex kata.

  • Custom User Avatar

    There's compilation warnings in the test code (fixture.c).

  • Default User Avatar

    you inspired my insanity ;)

  • Loading more items...