diff options
| author | Sebastiano Tronto <sebastiano.tronto@gmail.com> | 2021-11-11 21:37:34 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano.tronto@gmail.com> | 2021-11-11 21:37:34 +0100 |
| commit | 3568412f8f230774d0d11d7ed1c897424f95d3ef (patch) | |
| tree | 77223792d8c925a9b1fc32b3f4341e943b5f8209 /old/2021-05-26-before-restyle/utils.h | |
| parent | 67e1b5e6e6a2c917a2fe58a37a1382c982b1e5c5 (diff) | |
| download | nissy-3568412f8f230774d0d11d7ed1c897424f95d3ef.tar.gz nissy-3568412f8f230774d0d11d7ed1c897424f95d3ef.zip | |
Rewritten from scratch. Welocme nissy 2.0!
Diffstat (limited to '')
| -rw-r--r-- | old/2021-05-26-before-restyle/utils.h | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/old/2021-05-26-before-restyle/utils.h b/old/2021-05-26-before-restyle/utils.h new file mode 100644 index 0000000..4b6df8c --- /dev/null +++ b/old/2021-05-26-before-restyle/utils.h | |||
| @@ -0,0 +1,70 @@ | |||
| 1 | /* General utility functions */ | ||
| 2 | |||
| 3 | #ifndef UTILS_H | ||
| 4 | #define UTILS_H | ||
| 5 | |||
| 6 | #include <stdbool.h> | ||
| 7 | |||
| 8 | #define min(a,b) (((a) < (b)) ? (a) : (b)) | ||
| 9 | #define max(a,b) (((a) > (b)) ? (a) : (b)) | ||
| 10 | |||
| 11 | /* Some useful constants */ | ||
| 12 | #define pow2to11 2048 | ||
| 13 | #define pow2to12 4096 | ||
| 14 | #define pow3to7 2187 | ||
| 15 | #define pow3to8 6561 | ||
| 16 | #define pow12to4 20736 | ||
| 17 | #define factorial4 24 | ||
| 18 | #define factorial6 720 | ||
| 19 | #define factorial8 40320 | ||
| 20 | #define factorial12 479001600 | ||
| 21 | #define binom12on4 495 | ||
| 22 | #define binom8on4 70 | ||
| 23 | |||
| 24 | /* Generic utility functions */ | ||
| 25 | void swap(int *a, int *b); | ||
| 26 | void intarrcopy(int *src, int *dst, int n); | ||
| 27 | int sum(int *a, int n); | ||
| 28 | bool is_perm(int *a, int n); | ||
| 29 | bool is_perm(int *a, int n); | ||
| 30 | |||
| 31 | |||
| 32 | /* Standard mathematical functions */ | ||
| 33 | int powint(int a, int b); | ||
| 34 | int factorial(int n); | ||
| 35 | int binomial(int n, int k); | ||
| 36 | |||
| 37 | /* Converts the integer a to its representation in base b (first n digits | ||
| 38 | * only) and saves the result in r. */ | ||
| 39 | void int_to_digit_array(int a, int b, int n, int *r); | ||
| 40 | int digit_array_to_int(int *a, int n, int b); | ||
| 41 | |||
| 42 | /* Converts the first n-1 digits of a number to an array a of digits in base b; | ||
| 43 | * then adds one element to the array, so that the sum of the elements of a is | ||
| 44 | * zero modulo b. | ||
| 45 | * This is used for determing the edge orientation from an 11-bits integer or | ||
| 46 | * the corner orientation from a 7-trits integer. */ | ||
| 47 | void int_to_sum_zero_array(int x, int b, int n, int *a); | ||
| 48 | |||
| 49 | /* Converts a permutation on [0..(n-1)] into the integer i which is the index | ||
| 50 | * of the permutation in the sorted list of all n! such permutations. */ | ||
| 51 | int perm_to_index(int *a, int n); | ||
| 52 | void index_to_perm(int p, int n, int *r); | ||
| 53 | |||
| 54 | /* Determine the sign of a permutation */ | ||
| 55 | int perm_sign(int a[], int n); | ||
| 56 | |||
| 57 | /* Converts a k-element subset of a set from an array of n elements, of which k | ||
| 58 | * are 1 and n-k are 0, to its index in the sorted list of all such subsets. */ | ||
| 59 | int subset_to_index(int *a, int n, int k); | ||
| 60 | void index_to_subset(int s, int n, int k, int *r); | ||
| 61 | |||
| 62 | int ordered_subset_to_index(int *a, int n, int k); | ||
| 63 | void index_to_ordered_subset(int s, int n, int k, int *r); | ||
| 64 | |||
| 65 | void apply_permutation(int *perm, int *set, int n); | ||
| 66 | |||
| 67 | /* b[i] = (a[i]+b[i])%m for i=1,...,n */ | ||
| 68 | void sum_arrays_mod(int *a, int *b, int n, int m); | ||
| 69 | |||
| 70 | #endif | ||
