added interface and renamed functions

This commit is contained in:
celso 2023-01-06 00:52:30 -03:00
parent 21d674ed21
commit 4838718a58
2 changed files with 17 additions and 17 deletions

View File

@ -44,7 +44,7 @@ int main(int argc, char **argv){
case 2: case 2:
if (number >= 3 && number <= 17){ if (number >= 3 && number <= 17){
pair *pairs = malloc(sizeof(pair) * 4); pair *pairs = malloc(sizeof(pair) * 4);
int len = perm2(number, not_allowed, not_allowed_len, pairs); int len = skomb2(number, not_allowed, not_allowed_len, pairs);
printf("%d:\n", number); printf("%d:\n", number);
for (int i = 0; i < len; i++){ for (int i = 0; i < len; i++){
printf("\t%d + %d\n", pairs[i].x, pairs[i].y); printf("\t%d + %d\n", pairs[i].x, pairs[i].y);
@ -59,7 +59,7 @@ int main(int argc, char **argv){
case 3: case 3:
if (number >= 6 && number <= 24){ if (number >= 6 && number <= 24){
trio *trios = malloc(sizeof(trio) * 9); trio *trios = malloc(sizeof(trio) * 9);
int len = perm3(number, not_allowed, not_allowed_len, trios); int len = skomb3(number, not_allowed, not_allowed_len, trios);
printf("%d:\n", number); printf("%d:\n", number);
for (int i = 0; i < len; i++){ for (int i = 0; i < len; i++){
printf("\t%d + %d + %d\n", trios[i].x, trios[i].y, trios[i].z); printf("\t%d + %d + %d\n", trios[i].x, trios[i].y, trios[i].z);
@ -74,7 +74,7 @@ int main(int argc, char **argv){
case 4: case 4:
if (number >= 10 && number <= 30){ if (number >= 10 && number <= 30){
quartet *quartets = malloc(sizeof(quartet) * 12); quartet *quartets = malloc(sizeof(quartet) * 12);
int len = perm4(number, not_allowed, not_allowed_len, quartets); int len = skomb4(number, not_allowed, not_allowed_len, quartets);
printf("%d:\n", number); printf("%d:\n", number);
for (int i = 0; i < len; i++){ for (int i = 0; i < len; i++){
printf("\t%d + %d + %d + %d\n", quartets[i].x, quartets[i].y, quartets[i].z, quartets[i].w); printf("\t%d + %d + %d + %d\n", quartets[i].x, quartets[i].y, quartets[i].z, quartets[i].w);
@ -89,7 +89,7 @@ int main(int argc, char **argv){
case 5: case 5:
if (number >= 15 && number <= 35){ if (number >= 15 && number <= 35){
quintet *quintets = malloc(sizeof(quintet) * 12); quintet *quintets = malloc(sizeof(quintet) * 12);
int len = perm5(number, not_allowed, not_allowed_len, quintets); int len = skomb5(number, not_allowed, not_allowed_len, quintets);
printf("%d:\n", number); printf("%d:\n", number);
for (int i = 0; i < len; i++){ for (int i = 0; i < len; i++){
printf("\t%d + %d + %d + %d + %d\n", quintets[i].x, quintets[i].y, quintets[i].z, quintets[i].w, quintets[i].v); printf("\t%d + %d + %d + %d + %d\n", quintets[i].x, quintets[i].y, quintets[i].z, quintets[i].w, quintets[i].v);

View File

@ -42,12 +42,12 @@ typedef struct quintet{
int v; int v;
} quintet; } quintet;
void readline(char *line, int len); void readline(char *line, int len); /* read len ammount of characters from stdin into line */
int splitc_toi(char *line, int sep, int *dest); int splitc_toi(char *line, int sep, int *dest); /* split a char array of numbers into an int array, separator used between numbes must be provided in the function call (e.g. commas, spaces, etc.) */
int perm2(int number, int *not_allowed, int* not_allowed_len, pair *pairs); int skomb2(int number, int *not_allowed, int* not_allowed_len, pair *pairs); /* stores valid combinations that sum up to number respecting an int array of not allowed numbers with it's length in a pair array */
int perm3(int number, int *not_allowed, int* not_allowed_len, trio *trios); int skomb3(int number, int *not_allowed, int* not_allowed_len, trio *trios); /* same as above but with trios instead */
int perm4(int number, int *not_allowed, int* not_allowed_len, quartet *quartets); int skomb4(int number, int *not_allowed, int* not_allowed_len, quartet *quartets); /* same as above but with quartets instead */
int perm5(int number, int *not_allowed, int* not_allowed_len, quintet *quintets); int skomb5(int number, int *not_allowed, int* not_allowed_len, quintet *quintets); /* same as above but with quintets instead */
void readline(char *line, int len){ void readline(char *line, int len){
int i = 0; int i = 0;
@ -77,7 +77,7 @@ int splitc_toi(char *line, int sep, int *dest){
return j; return j;
} }
int perm2(int number, int* not_allowed, int* not_allowed_len, pair* dest){ int skomb2(int number, int* not_allowed, int* not_allowed_len, pair* dest){
int i, j, k; int i, j, k;
int skip; int skip;
k = 0; k = 0;
@ -101,7 +101,7 @@ int perm2(int number, int* not_allowed, int* not_allowed_len, pair* dest){
return k; return k;
} }
int perm3(int number, int *not_allowed, int *not_allowed_len, trio *trios){ int skomb3(int number, int *not_allowed, int *not_allowed_len, trio *trios){
int i, j, k; int i, j, k;
int skip, len; int skip, len;
k = 0; k = 0;
@ -121,7 +121,7 @@ int perm3(int number, int *not_allowed, int *not_allowed_len, trio *trios){
&& i < number){ && i < number){
not_allowed[*not_allowed_len] = i; not_allowed[*not_allowed_len] = i;
(*not_allowed_len)++; (*not_allowed_len)++;
len = perm2(number-i, not_allowed, not_allowed_len, pairs); len = skomb2(number-i, not_allowed, not_allowed_len, pairs);
if (len > 0){ if (len > 0){
for (j = 0; j < len; j++){ for (j = 0; j < len; j++){
if (i < pairs[j].x && i < pairs[j].y){ if (i < pairs[j].x && i < pairs[j].y){
@ -140,7 +140,7 @@ int perm3(int number, int *not_allowed, int *not_allowed_len, trio *trios){
return k; return k;
} }
int perm4(int number, int *not_allowed, int *not_allowed_len, quartet *quartets){ int skomb4(int number, int *not_allowed, int *not_allowed_len, quartet *quartets){
int i, j, k; int i, j, k;
int skip, len; int skip, len;
k = 0; k = 0;
@ -159,7 +159,7 @@ int perm4(int number, int *not_allowed, int *not_allowed_len, quartet *quartets)
if (i != number && number - i < 25 && number - i > 5){ if (i != number && number - i < 25 && number - i > 5){
not_allowed[*not_allowed_len] = i; not_allowed[*not_allowed_len] = i;
(*not_allowed_len)++; (*not_allowed_len)++;
len = perm3(number - i, not_allowed, not_allowed_len, trios); len = skomb3(number - i, not_allowed, not_allowed_len, trios);
if (len > 0){ if (len > 0){
for (j = 0; j < len; j++){ for (j = 0; j < len; j++){
if (i < trios[j].x && i < trios[j].y && i < trios[j].z){ if (i < trios[j].x && i < trios[j].y && i < trios[j].z){
@ -179,7 +179,7 @@ int perm4(int number, int *not_allowed, int *not_allowed_len, quartet *quartets)
return k; return k;
} }
int perm5(int number, int *not_allowed, int* not_allowed_len, quintet *quintets){ int skomb5(int number, int *not_allowed, int* not_allowed_len, quintet *quintets){
int i, j, k; int i, j, k;
int skip, len; int skip, len;
k = 0; k = 0;
@ -198,7 +198,7 @@ int perm5(int number, int *not_allowed, int* not_allowed_len, quintet *quintets)
if (i != number && number - i < 31 && number - i > 9){ if (i != number && number - i < 31 && number - i > 9){
not_allowed[*not_allowed_len] = i; not_allowed[*not_allowed_len] = i;
(*not_allowed_len)++; (*not_allowed_len)++;
len = perm4(number-i, not_allowed, not_allowed_len, quartets); len = skomb4(number-i, not_allowed, not_allowed_len, quartets);
if (len > 0){ if (len > 0){
for (j = 0; j < len; j++){ for (j = 0; j < len; j++){
if (i < quartets[j].x && i < quartets[j].y && i < quartets[j].z && i < quartets[j].w){ if (i < quartets[j].x && i < quartets[j].y && i < quartets[j].z && i < quartets[j].w){