From e1ebff51092baf5581b728baec05c52c4bb3445e Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sun, 12 Jul 2020 20:44:09 +0200 Subject: Added feature: scramble --- src/utils.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/utils.c') diff --git a/src/utils.c b/src/utils.c index c672453..5b7df06 100644 --- a/src/utils.c +++ b/src/utils.c @@ -65,6 +65,23 @@ void index_to_perm(int p, int n, int *r) { } } + +int perm_sign_array(int a[], int n) { + int ret = 0; + for (int i = 0; i < n; i++) + for (int j = i+1; j < n; j++) + if (a[i]>a[j]) + ret++; + return ret % 2; +} + +int perm_sign_int(int p, int n) { + int a[n]; + index_to_perm(p, n, a); + return perm_sign_array(a, n); +} + + /* Converts a k-element subset of a set with an element from an array of n * elements, of which k are 1 (or just non-zero) and n-k are 0, to its index * in the sorted list of all such subsets. -- cgit v1.3