aboutsummaryrefslogtreecommitdiff
path: root/old/utils.h
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano.tronto@gmail.com>2021-11-11 21:37:34 +0100
committerSebastiano Tronto <sebastiano.tronto@gmail.com>2021-11-11 21:37:34 +0100
commit3568412f8f230774d0d11d7ed1c897424f95d3ef (patch)
tree77223792d8c925a9b1fc32b3f4341e943b5f8209 /old/utils.h
parent67e1b5e6e6a2c917a2fe58a37a1382c982b1e5c5 (diff)
downloadnissy-3568412f8f230774d0d11d7ed1c897424f95d3ef.tar.gz
nissy-3568412f8f230774d0d11d7ed1c897424f95d3ef.zip
Rewritten from scratch. Welocme nissy 2.0!
Diffstat (limited to 'old/utils.h')
-rw-r--r--old/utils.h59
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
26void apply_permutation(int *perm, int *set, int n);
27void intarrcopy(int *src, int *dst, int n);
28bool is_perm(int *a, int n);
29bool is_subset(int *a, int n, int k);
30int sum(int *a, int n);
31void sum_arrays_mod(int *src, int *dst, int n, int m);
32void swap(int *a, int *b);
33
34/* Standard mathematical functions *******************************************/
35
36int binomial(int n, int k);
37int factorial(int n);
38int perm_sign(int a[], int n);
39int powint(int a, int b);
40
41/* Conversions to and from int (base b digits, permutations...) **************/
42
43int digit_array_to_int(int *a, int n, int b);
44void int_to_digit_array(int a, int b, int n, int *r);
45void int_to_sum_zero_array(int x, int b, int n, int *a);
46int invert_digits(int a, int b, int n);
47
48void index_to_perm(int p, int n, int *r);
49int perm_to_index(int *a, int n);
50
51void index_to_subset(int s, int n, int k, int *r);
52int subset_to_index(int *a, int n, int k);
53
54/* Am I not using these two?
55void index_to_ordered_subset(int s, int n, int k, int *r);
56int ordered_subset_to_index(int *a, int n, int k);
57*/
58
59#endif

Generated with cgit - Back to sebastiano.tronto.net