• Custom User Avatar

    i love how all of us have the same solution except the variety is on characters

    (not like there was any other way to solve this god forsaken puzzle)

  • Custom User Avatar

    sorry, bro, okey

  • Custom User Avatar

    Use spoiler flag next time, please, your posts here are visible on the homepage's discourse.

  • 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

    but wasn't the question about immutable param?
    (const std::string& str)?

  • Custom User Avatar

    For JohanWiltink, RealKenshiro and Unnamed, a new condition has been temporarily added: divisor % 2 == 1. When testing even cases, in the process, there were always some duplicates in the answer, by the approach used by myself, Unnamed and towc. I'm still researching on this to find a general solution for these cases. Thanks for pointing these issues.

  • Custom User Avatar

    I'm not sure if n % divisor != 0 is possible without more complicated stuff with high-precision fractions, but I have a version of the solution that seems to work for all other input.

  • Custom User Avatar

    n < 100000, divisor < n.
    In order to make the outputs exact, n % divisor == 0 condition holds for every test.

    These conditions are less general than possible, and seem arbitrary ( though they may enable additional performance if and when the reference solution starts giving correct answers ).

    0 <= n and 1 <= d <= triangular(n) ( or even slightly larger for small n ) would make sense, and you can put any arbitrary upper limit on n ( and thus d ) for performance reasons.

    I'd suggest including tests with n = 0, with d = 1, with d >= n, and with n, d coprime.

  • Custom User Avatar

    exactly my results

  • Custom User Avatar

    subset_sum(8, 4), 67) => 64

    subset_sum(14, 2), 8256) => 8192

    subset_sum(24, 8), 97141) => 97134

    subset_sum(46, 2), 626605) => 432337

    subset_sum(48, 4), 867746) => 864674

    subset_sum(68, 4), 342516) => 244212

  • Custom User Avatar

    no errors like these should pop up

    Seems like they do.

    I worry. I also worry you're going to need a lot of ifs.

  • Custom User Avatar

    It's not just cases where d == n either. See above for (8,4).

  • Custom User Avatar
    ghci> filter ((== 0) . (`mod` 4) . sum) $ filterM (const [False,True]) [1..8]
    [[],[8],[5,7],[5,7,8],[4],[4,8],[4,5,7],[4,5,7,8],[3,6,7],[3,6,7,8],[3,5],[3,5,8],[3,4,6,7],[3,4,6,7,8],[3,4,5],[3,4,5,8],[2,6],[2,6,8],[2,5,6,7],[2,5,6,7,8],[2,4,6],[2,4,6,8],[2,4,5,6,7],[2,4,5,6,7,8],[2,3,7],[2,3,7,8],[2,3,5,6],[2,3,5,6,8],[2,3,4,7],[2,3,4,7,8],[2,3,4,5,6],[2,3,4,5,6,8],[1,7],[1,7,8],[1,5,6],[1,5,6,8],[1,4,7],[1,4,7,8],[1,4,5,6],[1,4,5,6,8],[1,3],[1,3,8],[1,3,5,7],[1,3,5,7,8],[1,3,4],[1,3,4,8],[1,3,4,5,7],[1,3,4,5,7,8],[1,2,6,7],[1,2,6,7,8],[1,2,5],[1,2,5,8],[1,2,4,6,7],[1,2,4,6,7,8],[1,2,4,5],[1,2,4,5,8],[1,2,3,6],[1,2,3,6,8],[1,2,3,5,6,7],[1,2,3,5,6,7,8],[1,2,3,4,6],[1,2,3,4,6,8],[1,2,3,4,5,6,7],[1,2,3,4,5,6,7,8]]
    ghci> length $ filter ((== 0) . (`mod` 4) . sum) $ filterM (const [False,True]) [1..8]
    64
    

    Why test.assert_equals(subset_sum(8, 4), 67) when the answer is apparently 64 ?

    Lots of expected answers ( half of 'em, to be exact, even excluding the removed (2,2) ) in the example tests are still wrong according to my solution.

  • Custom User Avatar

    And the reference solution is wrong for many other cases: (9, 9) -> expected 60, (15, 15) -> expected 2192. I sumbitted this version to see what should be done to generalize it and wasn't really expecting it to pass all the tests.

  • Loading more items...