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/utils.h | |
| parent | 67e1b5e6e6a2c917a2fe58a37a1382c982b1e5c5 (diff) | |
| download | nissy-3568412f8f230774d0d11d7ed1c897424f95d3ef.tar.gz nissy-3568412f8f230774d0d11d7ed1c897424f95d3ef.zip | |
Rewritten from scratch. Welocme nissy 2.0!
Diffstat (limited to 'old/utils.h')
| -rw-r--r-- | old/utils.h | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/old/utils.h b/old/utils.h new file mode 100644 index 0000000..ee8ac6e --- /dev/null +++ b/old/utils.h | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | #ifndef UTILS_H | ||
| 2 | #define UTILS_H | ||
| 3 | |||
| 4 | #include <stdbool.h> | ||
| 5 | #include <stdlib.h> | ||
| 6 | |||
| 7 | /* Constants and macros *****************************************************/ | ||
| 8 | |||
| 9 | #define pow2to11 2048 | ||
| 10 | #define pow2to12 4096 | ||
| 11 | #define pow3to7 2187 | ||
| 12 | #define pow3to8 6561 | ||
| 13 | #define pow12to4 20736 | ||
| 14 | #define factorial4 24 | ||
| 15 | #define factorial6 720 | ||
| 16 | #define factorial8 40320 | ||
| 17 | #define factorial12 479001600 | ||
| 18 | #define binom12on4 495 | ||
| 19 | #define binom8on4 70 | ||
| 20 | |||
| 21 | #define min(a,b) (((a) < (b)) ? (a) : (b)) | ||
| 22 | #define max(a,b) (((a) > (b)) ? (a) : (b)) | ||
| 23 | |||
| 24 | /* Generic utility functions *************************************************/ | ||
| 25 | |||
| 26 | void apply_permutation(int *perm, int *set, int n); | ||
| 27 | void intarrcopy(int *src, int *dst, int n); | ||
| 28 | bool is_perm(int *a, int n); | ||
| 29 | bool is_subset(int *a, int n, int k); | ||
| 30 | int sum(int *a, int n); | ||
| 31 | void sum_arrays_mod(int *src, int *dst, int n, int m); | ||
| 32 | void swap(int *a, int *b); | ||
| 33 | |||
| 34 | /* Standard mathematical functions *******************************************/ | ||
| 35 | |||
| 36 | int binomial(int n, int k); | ||
| 37 | int factorial(int n); | ||
| 38 | int perm_sign(int a[], int n); | ||
| 39 | int powint(int a, int b); | ||
| 40 | |||
| 41 | /* Conversions to and from int (base b digits, permutations...) **************/ | ||
| 42 | |||
| 43 | int digit_array_to_int(int *a, int n, int b); | ||
| 44 | void int_to_digit_array(int a, int b, int n, int *r); | ||
| 45 | void int_to_sum_zero_array(int x, int b, int n, int *a); | ||
| 46 | int invert_digits(int a, int b, int n); | ||
| 47 | |||
| 48 | void index_to_perm(int p, int n, int *r); | ||
| 49 | int perm_to_index(int *a, int n); | ||
| 50 | |||
| 51 | void index_to_subset(int s, int n, int k, int *r); | ||
| 52 | int subset_to_index(int *a, int n, int k); | ||
| 53 | |||
| 54 | /* Am I not using these two? | ||
| 55 | void index_to_ordered_subset(int s, int n, int k, int *r); | ||
| 56 | int ordered_subset_to_index(int *a, int n, int k); | ||
| 57 | */ | ||
| 58 | |||
| 59 | #endif | ||
