Ad
  • Custom User Avatar

    Yes, but no.
    Please use decimal "ones" or "zeros" when counting in decimal - binary "ones" and "zeros", though technically the same, don't like it very much to be misgendered that way - because they identify as binary :D

  • Custom User Avatar

    Thats so nice and clean - tried similar, but didn't knew you could use a for-loop as a lazy while-loop like that and I
    also wasn't sure if bitshift-equals is a legal expression.

  • Default User Avatar

    why the use of size_t insead of unsigned?

  • Default User Avatar

    0 is true

    == 0 is false

    < 0 is true ?

  • Default User Avatar

    how the loop stops when value == 0? can you explain?

  • Custom User Avatar

    your func is called is_odd but thats a is_even func 😂 wtf

  • Custom User Avatar
  • Custom User Avatar

    I made such a dreadful solution in comparison to this one

  • Default User Avatar

    don't we need to free the memory at some point after we use it ?

  • Custom User Avatar

    I don't see it either, but since the code uses the nonstandard function strrev(), it's automatically non-portable even without plusDot().

  • Custom User Avatar

    may i know where does plusDot come from?

  • Default User Avatar

    Your code has a bug.
    Let say g=3, m=3, n=4
    Result: [0, 3] // Should be[0,0]

    Let say g=5, m=5, n=6
    Resutl: [0,6] // Should be [0,0]

    Your function will getting problem when g=m and n > m + 1 (or more)
    Your problem code is here:

    if (candidates[1] - candidates[0] == (long long)g) {
    return candidates;

    For the first iteration
    candidate[1] will fill with first prime number
    but candidate[0] is 0.
    So, when first prime - 0 == g (your code wrong here)
    // you should start compare candidate[0] and candidate[1] after these two values are filled

  • Default User Avatar

    I do not find this code "Best Practices" or "Clever". There are two bugs in the solution.

    Bug 1: Deadlock
    With some input values variable v will overflow, become negative and the while loop will go in deadlock.

    Test with the max value for a 64-bit integer.
    testequal(9223372036854775807, -1);

    Bug 2: Precision loss with double conversion
    The inputs to pow function are converted to double and the output is converted back to integer. A double can't represent whole numbers bigger than 2^53.

    Test with the maximum number of squares possible for an 64-bit integer.
    testequal(9223193340756366400, 77935);

  • Custom User Avatar

    may anyone explain the code started from b += c > 1 ? I don't understand why c, which is index, is added to pointer b. This expression will give value of b after assigning, which must be > 1. Also, will this update pointer b and left some memory unused?
    Besides, as a terminating null character is automatically appended after the content written in snprintf, how can the code solve this problem?

  • Default User Avatar

    Cool to update pointer b with snprintf!

  • Loading more items...