diff options
| author | Sebastiano Tronto <sebastiano.tronto@gmail.com> | 2020-07-12 20:44:09 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano.tronto@gmail.com> | 2020-07-12 20:44:09 +0200 |
| commit | e1ebff51092baf5581b728baec05c52c4bb3445e (patch) | |
| tree | 8e3cc3fa0cf10bbe35a3bacfba8e1d96f850b058 /src/utils.c | |
| parent | 0fe7c8b43c50ae5701463acbb186a6fe0f53a773 (diff) | |
| download | nissy-e1ebff51092baf5581b728baec05c52c4bb3445e.tar.gz nissy-e1ebff51092baf5581b728baec05c52c4bb3445e.zip | |
Added feature: scramble
Diffstat (limited to '')
| -rw-r--r-- | src/utils.c | 17 |
1 files changed, 17 insertions, 0 deletions
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) { | |||
| 65 | } | 65 | } |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | |||
| 69 | int perm_sign_array(int a[], int n) { | ||
| 70 | int ret = 0; | ||
| 71 | for (int i = 0; i < n; i++) | ||
| 72 | for (int j = i+1; j < n; j++) | ||
| 73 | if (a[i]>a[j]) | ||
| 74 | ret++; | ||
| 75 | return ret % 2; | ||
| 76 | } | ||
| 77 | |||
| 78 | int perm_sign_int(int p, int n) { | ||
| 79 | int a[n]; | ||
| 80 | index_to_perm(p, n, a); | ||
| 81 | return perm_sign_array(a, n); | ||
| 82 | } | ||
| 83 | |||
| 84 | |||
| 68 | /* Converts a k-element subset of a set with an element from an array of n | 85 | /* Converts a k-element subset of a set with an element from an array of n |
| 69 | * elements, of which k are 1 (or just non-zero) and n-k are 0, to its index | 86 | * elements, of which k are 1 (or just non-zero) and n-k are 0, to its index |
| 70 | * in the sorted list of all such subsets. | 87 | * in the sorted list of all such subsets. |
