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)
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 :)
I agree with you. I was writting a more thoughtful response to your reply, and I just decided to delete it since it would wrap around to say, "I agree with you". I like your insight, though. It would be nice to have more conversations like this with you ;)
kindly do not post solutions like this, as it goes to the main comment thread where nobody wants to see it
#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
}
}
tester("pneumonoultramicroscopicsilicovolcanoconiosis", "sisoinoconaclovociliscipocsorcimartluonomuenp");
Merged.
Fixed spelling mistake in C translation.
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.
Yea, I should've chosen a better name. Thanks :D
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 :)
once again, dont make it look good- make it look intimidating... :)
umm really?????
I just ported their code to C. I didn't add any extra features to detect foul play.
u really wanna do this? i dont even know c that much, just the basics :(
Would you mind your language a bit.
This comment has been reported as abusive
I agree with you. I was writting a more thoughtful response to your reply, and I just decided to delete it since it would wrap around to say, "I agree with you". I like your insight, though. It would be nice to have more conversations like this with you ;)
Loading more items...