aboutsummaryrefslogtreecommitdiff
path: root/src/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 /src/utils.h
parent67e1b5e6e6a2c917a2fe58a37a1382c982b1e5c5 (diff)
downloadnissy-3568412f8f230774d0d11d7ed1c897424f95d3ef.tar.gz
nissy-3568412f8f230774d0d11d7ed1c897424f95d3ef.zip
Rewritten from scratch. Welocme nissy 2.0!
Diffstat (limited to 'src/utils.h')
-rw-r--r--src/utils.h91
1 files changed, 37 insertions, 54 deletions
diff --git a/src/utils.h b/src/utils.h
index 45a6302..80c33ae 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -1,58 +1,41 @@
1#define min(a,b) (((a) < (b)) ? (a) : (b)) 1#ifndef UTILS_H
2#define max(a,b) (((a) > (b)) ? (a) : (b)) 2#define UTILS_H
3#define abs(a) (((a) > 0) ? (a) : (-(a)))
4 3
5/* Some useful constants */ 4#include <stdbool.h>
6#define pow2to11 2048 5#include <stdlib.h>
7#define pow2to12 4096 6#include <string.h>
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 7
18void swap(int *a, int *b); 8#define POW2TO6 64ULL
9#define POW2TO11 2048ULL
10#define POW2TO12 4096ULL
11#define POW3TO7 2187ULL
12#define POW3TO8 6561ULL
13#define FACTORIAL4 24ULL
14#define FACTORIAL6 720ULL
15#define FACTORIAL7 5040ULL
16#define FACTORIAL8 40320ULL
17#define FACTORIAL12 479001600ULL
18#define BINOM12ON4 495ULL
19#define BINOM8ON4 70ULL
20#define MIN(a,b) (((a) < (b)) ? (a) : (b))
21#define MAX(a,b) (((a) > (b)) ? (a) : (b))
19 22
20/* Hardcoded factorial of small numbers (n<=12). */ 23void apply_permutation(int *perm, int *set, int n);
21extern int factorial[13]; 24int binomial(int n, int k);
22 25int digit_array_to_int(int *a, int n, int b);
23/* Converts the integer a to its representation in base b (first n digits 26int factorial(int n);
24 * only) and saves the result in r. */ 27void index_to_perm(int p, int n, int *r);
25void int_to_digit_array(int a, int b, int n, int *r); 28void index_to_subset(int s, int n, int k, int *r);
26 29void int_to_digit_array(int a, int b, int n, int *r);
27/* Converts the array of n digits a to a integer using base b. */ 30void int_to_sum_zero_array(int x, int b, int n, int *a);
28int digit_array_to_int(int *a, int n, int b); 31int invert_digits(int a, int b, int n);
29 32bool is_perm(int *a, int n);
30/* Converts a permutation on [0..(n-1)] into the integer i which is the index 33bool is_subset(int *a, int n, int k);
31 * of the permutation in the sorted list of all n! such permutations. 34int perm_sign(int *a, int n);
32 * Only works for n<=12. */ 35int perm_to_index(int *a, int n);
33int perm_to_index(int *a, int n); 36int powint(int a, int b);
34 37int subset_to_index(int *a, int n, int k);
35/* Converts a permutation index to the actual permutation as an array 38void sum_arrays_mod(int *src, int *dst, int n, int m);
36 * (see perm_to_index) and saves the result to r. */ 39void swap(int *a, int *b);
37void index_to_perm(int p, int n, int *r);
38
39/* Determine the sign of a permutation, either in integer or array format. */
40int perm_sign_array(int a[], int n);
41int perm_sign_int(int p, int n);
42
43/* Converts a k-element subset of a set with an element from an array of n
44 * elements, of which k are 1 and n-k are 0, to its index in the sorted list
45 * of all such subsets.
46 * Works only for n <= 12. */
47int subset_to_index(int *a, int n, int k);
48
49/* Inverse of the above */
50void index_to_subset(int s, int n, int k, int *r);
51
52/* Converts the first n-1 digits of a number to an array a of digits in base b;
53 * then adds one element to the array, so that the sum of the elements of a is
54 * zero modulo b.
55 * This is used for determing the edge orientation from an 11-bits integer or
56 * the corner orientation from a 7-trits integer. */
57void int_to_sum_zero_array(int x, int b, int n, int *a);
58 40
41#endif

Generated with cgit - Back to sebastiano.tronto.net