Ad
  • Custom User Avatar

    Its not I know i'm adding randoms

  • Custom User Avatar

    I created this one as I did not found what I was looking for elsewhere
    When a 1 kuy come into a 7 kyu kata just to say that's 'trivial', it does not benefit anybody either.
    Maybe you should just relax ?

  • Custom User Avatar

    Don't hesitate to tell me if the task descrption is unclear, i'll update it

  • Custom User Avatar

    I guess the problem may come this line :

    long long** result = (long long**)calloc(row, sizeof(long long));

    try to declare result as :

    long long (*result)[2] = calloc(row, sizeof(lst[0]));

  • Custom User Avatar

    Very efficient solution, indeed, i'm wondering where are defined the lcmu and gdci functions and if we can use them in other katas ?

  • Custom User Avatar

    C translation just Kumited with random tests ;)

  • Custom User Avatar

    Too bad that the answer was NOT the real maximum result you can make with a b and c using + * and ().

    By example, here expression_matter(1,3,1) == 5 // 1+3+1
    But the real maximum with tose numbers would be 3*(1+1)=6

  • Custom User Avatar

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

  • Custom User Avatar

    $ man 3 qsort
    This is a quick sorting algorithm, it would prevent you to write the sort(char*,int) function.

  • Custom User Avatar

    This code is very short that is a good point. Unfortunately it's vulnarable to buffer overflows. The output storage 'buffer' is allocated with a fixed size of 500 bytes, checks have to be done to do not exceed this limit.

    Concerning the efficiency, the code :

      sprintf(buffer + strlen(buffer), arg);
      j += strlen(arg);
    

    Could be shorten to :

      j += sprintf(buffer + j, arg); // as j is the offset in the buffer, and sprintf returns the # bytes written
    

    We save time by not calling strlen function

    And the code :

      arg = va_arg(args, int);
      char* numberBuffer = calloc(10, sizeof(char));
      sprintf(numberBuffer, "%d", arg);
      sprintf(buffer + strlen(buffer), numberBuffer);
      j += strlen(numberBuffer);  
    

    Can be reduced to :

      j += sprintf(buffer + j, "%d", va_arg(args, int));
    

    There is no need here to use dynamic memory, neither to call strlen.

    Hope it helps :)