Ad
  • Custom User Avatar

    A reasonable optimizing compiler will produce the same machine code regardless of whether the variable is defined before the if-check or after it. Initializing local variables has no effects visible to callers so the compiler may freely reorder the code as it sees fit.

    The reason is just style and clarity. First of all, it's common to add preconditions to the start of a function. If there are no items, we already know the answer and we can return right away. Second, it's generally a good idea to keep the scope of variables as small as possible.

    Of course, in such a short function it doesn't really matter, but if a long function defines variable in the very beginning and uses it a lot later, can you be sure that there are no uses between? You have to carefully read through the whole function to check if there are other references.

  • Custom User Avatar

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

  • Custom User Avatar

    What abt thease brackets inside the parentheses, could you explain why he puts parenteses if he's reffering to the array, and why putting - between the two extremes of the array and most importantly, why the hell it works inside the two double quotaions :) m just curious to know more about thease notation :)

  • Custom User Avatar

    Fixed.

  • Custom User Avatar

    Maybe, but speed isn't usually particularly important with this kind of string replacement. Your solution appears to be about 9x faster, which might matter in some cases, but definitely doesn't for this kata-- or most real-world applications-- but 8 lines vs 1 for a simple string character replacement function does. 2.6 million operations/s is plenty.

  • Default User Avatar

    I did finish it using 0.082 for R. I would argue though that the description does not say it is, but rather a calculation where one of the factors is 0.082.

  • Custom User Avatar

    Those are units, and the only one left is atm when you return the pressure. R is a constant.

  • Default User Avatar

    Excactly where does R come from ?

    The description says "R=0.082dm3⋅atm⋅K−1⋅mol−1", but atm isn't anywhere to be found. Unless you count the return value.
    Being a level kyu8 kata it couldn't hurt to give up the number intended used for mol and atm.

  • Custom User Avatar

    That's its numeric value with the units used in the formula, yes.

  • Custom User Avatar
  • Custom User Avatar
  • Custom User Avatar

    Parameter names are fixed in this C fork and this NASM fork.

  • Default User Avatar

    You can change gM to mass, mM to molarMass.

  • Default User Avatar

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

  • Custom User Avatar

    gM are given mass, mM are molar mass, and they are given in the same order as in the "Input" paragraph of the description.

    But you are right, they are confusing, I will add some description.

  • Loading more items...