Ad
  • Custom User Avatar

    I've been thinking about it too

  • Custom User Avatar

    you used an extra variable r in your code for the same purpose, only it was a pointer instead of an index

  • Custom User Avatar

    The kata was approved overnight when I do not have an access to my laptop.

    However, I would like to ask you, what do you mean by in C, the "value = 2" in description is never used? The original task was made in Python and the author of the C translation did not change the description, stating that the description to the katas should be language-agnostic.

    About the definition of what "trace" is, I agree. By marking this task as "beginner-friendly", I should have stated the key things.

  • Custom User Avatar

    TIL on Wikipedia:

    the trace of a square matrix A, denoted tr(A), is the sum of the elements on its main diagonal, a[1][1] + a[2][2] + ⋯ + a[n][n]. It is only defined for a square matrix (n × n).

    Indeed, it would be good to add this term & link to the description, as so many other katas also do.

  • Custom User Avatar

    indeed, iBits+2 instead of n+2... but i dunno why i even did a malloc instead of just a fixed sizeof(int)*8+2 byte array or something...

  • Custom User Avatar

    cuz it looks beautiful!

  • Custom User Avatar

    looks elegant but inefficient indeed.

  • Custom User Avatar

    Your array without -199:

    product is 8.101683605554995e+142
    sum is -832
    q will be 9.737600487445906e+139
    

    Your array without 196:

    product is -8.22568896686451e+142
    sum is -1227
    q will be 6.703902988479633e+139
    

    q is obviously smaller when removing 196. I have no idea why your excel is giving you the wrong numbers. It's entirely possible that your implementation in excel is incorrect, or maybe excel is running into some kind of overflow error. Your values of q are obviously incorrect, though. You are dividing the product of the array by the sum of the array, with very few exceptions (and this array does not fit any of the exception criteria) this will produce a q value greater than 1, but your q values are very close to 0, and you can manually do the sums and products yourself to see that the q values you should be producing for this particular array should be very large, and so your q values are far from correct.

    After looking at your code, you may want to pay attention to the data type that you use to hold your product total values keeping in mind that the product total will be very very large in some cases like the above example.

  • Custom User Avatar

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

  • Custom User Avatar

    my passing python solution says 196 and also what you say isn't reasonable after reading the instructions

  • Custom User Avatar
  • Custom User Avatar

    i < res.size() so only initialized elements are accessed.

  • Custom User Avatar

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

  • Custom User Avatar

    Me too! It is so long since I wrote this.

    The return *sz, ret; is really same as just return ret; but I think I was trying to emphasise that the sz is also a "returned" value. Probably it was unnecessarily clever (?) and caused more confusion than anything else.

  • Custom User Avatar

    I believe he meant "CdWr oeas", but he made a typo.

  • Loading more items...