-
Notifications
You must be signed in to change notification settings - Fork 4
/
FastCP.c
43 lines (40 loc) · 1.01 KB
/
FastCP.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int* get_tuple_by_index(int** setarr, int index, int numberofsets, int setlenarr[])
{
// Get a tuple of the Cartesian Product of given sets at given index
int i, element;
int* tuple = malloc(numberofsets * sizeof(int));
for (i = numberofsets - 1; i >= 0; i--)
{
element = setarr[i][index % setlenarr[i]];
tuple[i] = element;
index /= setlenarr[i];
}
return tuple;
}
void printl(int *arr)
{
// Prints in tuple format
printf("(");
for (int i = 0; i < 3; i++)
{
printf("%d, ", arr[i]);
}
printf("\b\b)\n");
}
void main()
{
int firstset[256], secondset[256], thirdset[256], i;
static int *result;
for (i = 0; i < 256; i++)
{
firstset[i] = i + 1;
secondset[i] = i + 1;
thirdset[i] = i + 1;
}
int *setarr[] = {firstset, secondset, thirdset};
result = get_tuple_by_index(setarr, 11564203, 3, (int[]) { 256, 256, 256 });
printl(result);
}