diff options
| author | Sebastiano Tronto <sebastiano.tronto@gmail.com> | 2020-06-21 23:01:57 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano.tronto@gmail.com> | 2020-06-21 23:01:57 +0200 |
| commit | 0e8d73bb3edcc8bdff6e3ded442b66f68265059a (patch) | |
| tree | 4f92deb9ace97e79332c0e7ce390b76b81aeaae9 /src/utils.h | |
| parent | 4e359b44ce111b04cc4d2b28033fba4ab4e6e989 (diff) | |
| download | nissy-0e8d73bb3edcc8bdff6e3ded442b66f68265059a.tar.gz nissy-0e8d73bb3edcc8bdff6e3ded442b66f68265059a.zip | |
First push
Diffstat (limited to 'src/utils.h')
| -rw-r--r-- | src/utils.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/utils.h b/src/utils.h new file mode 100644 index 0000000..b24ccb2 --- /dev/null +++ b/src/utils.h | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | #define min(a,b) (((a) < (b)) ? (a) : (b)) | ||
| 2 | #define max(a,b) (((a) > (b)) ? (a) : (b)) | ||
| 3 | #define abs(a) (((a) > 0) ? (a) : (-(a))) | ||
| 4 | |||
| 5 | /* Some useful constants */ | ||
| 6 | #define pow2to11 2048 | ||
| 7 | #define pow2to12 4096 | ||
| 8 | #define pow3to7 2187 | ||
| 9 | #define pow3to8 6561 | ||
| 10 | #define pow12to4 20736 | ||
| 11 | #define factorial4 24 | ||
| 12 | #define factorial6 720 | ||
| 13 | #define factorial8 40320 | ||
| 14 | #define factorial12 479001600 | ||
| 15 | #define binom12on4 495 | ||
| 16 | #define binom8on4 70 | ||
| 17 | |||
| 18 | void swap(int *a, int *b); | ||
| 19 | |||
| 20 | /* Hardcoded factorial of small numbers (n<=12). */ | ||
| 21 | extern int factorial[13]; | ||
| 22 | |||
| 23 | /* Converts the integer a to its representation in base b (first n digits | ||
| 24 | * only) and saves the result in r. */ | ||
| 25 | void int_to_digit_array(int a, int b, int n, int *r); | ||
| 26 | |||
| 27 | /* Converts the array of n digits a to a integer using base b. */ | ||
| 28 | int digit_array_to_int(int *a, int n, int b); | ||
| 29 | |||
| 30 | /* Converts a permutation on [0..(n-1)] into the integer i which is the index | ||
| 31 | * of the permutation in the sorted list of all n! such permutations. | ||
| 32 | * Only works for n<=12. */ | ||
| 33 | int perm_to_index(int *a, int n); | ||
| 34 | |||
| 35 | /* Converts a permutation index to the actual permutation as an array | ||
| 36 | * (see perm_to_index) and saves the result to r. */ | ||
| 37 | void index_to_perm(int p, int n, int *r); | ||
| 38 | |||
| 39 | /* Converts a k-element subset of a set with an element from an array of n | ||
| 40 | * elements, of which k are 1 and n-k are 0, to its index in the sorted list | ||
| 41 | * of all such subsets. | ||
| 42 | * Works only for n <= 12. */ | ||
| 43 | int subset_to_index(int *a, int n, int k); | ||
| 44 | |||
| 45 | /* Inverse of the above */ | ||
| 46 | void index_to_subset(int s, int n, int k, int *r); | ||
| 47 | |||
| 48 | /* Converts the first n-1 digits of a number to an array a of digits in base b; | ||
| 49 | * then adds one element to the array, so that the sum of the elements of a is | ||
| 50 | * zero modulo b. | ||
| 51 | * This is used for determing the edge orientation from an 11-bits integer or | ||
| 52 | * the corner orientation from a 7-trits integer. */ | ||
| 53 | void int_to_sum_zero_array(int x, int b, int n, int *a); | ||
| 54 | |||
