Ad
  • Custom User Avatar

    This is a minor and admittedly picky suggestion that doesn't affect the Kata's functionality. The original description was likely written with an object-oriented language in mind, which explains the reference to a "method".

    The only change I'd suggest is updating the C language description to use the term "function" instead of "method", since C doesn't support methods in the OOP sense. Here's a fork with that small wording adjustment, in case you'd like to merge it:
    https://www.codewars.com/kumite/68912a45d61d89e470fe3b6c?sel=68912a45d61d89e470fe3b6c

    Again, this is purely a cosmetic change.

  • Custom User Avatar
  • Custom User Avatar

    Didn't know that refactoring could have concepts but as for OP request, this code has to be "intimidating".
    As for me, i decided to go with no libs, but the result is less funky than expected. For the pseudo-random algo I went for Blum Blum Shub and stitched it with some defines.

  • Custom User Avatar

    I've updated the description with a detailed specification of the input.

  • Custom User Avatar

    You need to specify the input in the description. e.g. the image is represented as single char * split over multiple lines, it will always have length/width of blah, holes in circles will never include the circle's edge, etc.

  • Custom User Avatar

    kindly do not post solutions like this, as it goes to the main comment thread where nobody wants to see it

  • Custom User Avatar

    #include <stddef.h>
    #include <stdlib.h>

    int *twin_sum_solutions(int *input, size_t input_len, size_t *output_len) {
    if (input_len < 2) {
    *output_len = 0;
    return NULL; // Return NULL if there are no pairs
    }

    int *res = malloc(input_len * sizeof(int));  // Allocate memory for the result
    if (!res) {
        *output_len = 0;
        return NULL;  // Return NULL if memory allocation fails
    }
    
    *output_len = 0;  // Initialize the result counter
    
    for (size_t i = 0; i < input_len - 1; i++) {
        if (input[i] == input[i + 1]) {  // Check if it's a matching pair
            res[*output_len] = input[i] * 2;  // Store the "twin sum"
            (*output_len)++;
            i++;  // Skip the next element as it's already processed
        }
    }
    
    // Resize the memory to the correct size of results
    int *final_result = realloc(res, *output_len * sizeof(int));
    
    // If realloc fails and there are results, free the memory
    if (!final_result && *output_len > 0) {
        free(res);
        *output_len = 0;
        return NULL;
    }
    
    return final_result;  // Return the result (or NULL if no results)
    

    }

  • Custom User Avatar

    tester("pneumonoultramicroscopicsilicovolcanoconiosis", "sisoinoconaclovociliscipocsorcimartluonomuenp");

  • Custom User Avatar

    Merged.

  • Custom User Avatar

    Fixed spelling mistake in C translation.

  • Custom User Avatar

    I think you do not need len. It is a dice so the number of faces is always 6. Unless you are considering a dice for dungeons and dragons.

  • Custom User Avatar

    Yea, I should've chosen a better name. Thanks :D

  • Custom User Avatar

    love it, just the name of prod is a bit misleading, took me a bit to realize what you wanted to do
    its actually a denominator of the quotient, so when i(sum-i) is maximum, q is minimum
    nice :)

  • Custom User Avatar

    once again, dont make it look good- make it look intimidating... :)

  • Custom User Avatar

    umm really?????

  • Loading more items...