Ad
  • Custom User Avatar

    This seems like recursive-math thinking to me; and translating it into code is trivial. It's the base for dynamic-programming algorithms, I think.
    :(, I personally never caught this math thinking skill. But it's great, inspiring; if I see some more of these, I may be able to catch this thinking-technique myself :).

  • Default User Avatar
  • Custom User Avatar

    Like that one, same as my idea.

  • Custom User Avatar

    Just curious, how would you expand the query to include months with no payment information in the output?

  • Custom User Avatar

    Old question, but since there's no answer yet:

    That's how arithmetic operations work in most programming languages, and sql. If you have an operation, e.g. "+" on two different types, the runtime tries to match the types, usually by casting the "lower precision" type value to the "higher precision" type. The result is then of the common higher precision type. If you transform (or better cast) one value to a data type with higher precision, the other operand will be casted automatically to match. (e.g. int + int = int, float + int = float, float + double = double) If such a conversion is not possible you get an error.

  • Custom User Avatar

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

  • Custom User Avatar

    How did this compile? I had a very similar solution but I got a compiler error about undefined reference to ackermann::value.
    This could be fixed by creating an instance of the static value (see Unnamed's solution) or using an enum.

  • Custom User Avatar

    I didn't particularly like this kata. We are dealing with randomnes here, which makes the tests unreliable. Even a correct solution might fail at times. Imagine such a behaviour on a real build/test server for real projects.

  • Default User Avatar

    Yea, at least i will remember it forever i guess haha

  • Default User Avatar

    You're right ! The first part is completely useless. I can't remember why I did that. It was my first time using vectors.

  • Custom User Avatar

    There's probably no performance benefit over a well written loop. But the standard algorithms are allways better than a bad loop. The real benefit is in "readability of intention". In nested loops it's hard to see what was intended, the standard algorithms state pretty well what they are doing, e.g. copy something if -a condition is true- and you can be sure they do that correctly and efficiently. I must admit that the (nested) lambdas look a little scary at first, but once you get the hang of it the code becomes easier to understand.

  • Custom User Avatar

    Looks pretty similar to my first solution. For readability I moved the code of the lambda expressions into separate functions and used std::bind to make the predicates.

  • Custom User Avatar

    Or add using namespace std; in the initial code.

  • Custom User Avatar

    The C++ given stub and test code doesn't even compile. In any case it should be std::vector.
    In C++ 11 or 14 the vectors should be initialized by initializer lists like this instead:

        const std::vector<int> a1 {121, 144, 19, 161, 19, 144, 19, 11};
        const std::vector<int> b2 {11*11, 121*121, 144*144, 19*19, 161*161, 19*19, 144*144, 19*19};
    
  • Custom User Avatar

    This solution will fail if there are more than 101 followers. There's no need to write your own "number to string". Since C++11 there's std::to_string which will do the trick.

  • Loading more items...