aboutsummaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/utils.c b/src/utils.c
index e0d3268..cbf951e 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -1,3 +1,5 @@
1#define UTILS_C
2
1#include "utils.h" 3#include "utils.h"
2 4
3void 5void
@@ -159,24 +161,24 @@ is_perm(int *a, int n)
159{ 161{
160 int *aux = malloc(n * sizeof(int)); 162 int *aux = malloc(n * sizeof(int));
161 int i; 163 int i;
164 bool ret = true;
162 165
163 for (i = 0; i < n; i++) 166 for (i = 0; i < n; i++)
164 aux[i] = 0; 167 aux[i] = 0;
165 168
166 for (i = 0; i < n; i++) { 169 for (i = 0; i < n; i++) {
167 if (a[i] < 0 || a[i] >= n) 170 if (a[i] < 0 || a[i] >= n)
168 return false; 171 ret = false;
169 else 172 else
170 aux[a[i]] = 1; 173 aux[a[i]] = 1;
171 } 174 }
172 175
173 for (i = 0; i < n; i++) 176 for (i = 0; i < n; i++)
174 if (!aux[i]) 177 if (!aux[i])
175 return false; 178 ret = false;
176 179
177 free(aux); 180 free(aux);
178 181 return ret;
179 return true;
180} 182}
181 183
182bool 184bool
@@ -195,7 +197,7 @@ perm_sign(int *a, int n)
195{ 197{
196 int i, j, ret = 0; 198 int i, j, ret = 0;
197 199
198 if (!is_perm(a,n)) 200 if (!is_perm(a, n))
199 return -1; 201 return -1;
200 202
201 for (i = 0; i < n; i++) 203 for (i = 0; i < n; i++)
@@ -211,7 +213,7 @@ perm_to_index(int *a, int n)
211 int i, j, c, ret = 0; 213 int i, j, c, ret = 0;
212 214
213 if (!is_perm(a, n)) 215 if (!is_perm(a, n))
214 return -1; 216 return factorial(n);
215 217
216 for (i = 0; i < n; i++) { 218 for (i = 0; i < n; i++) {
217 c = 0; 219 c = 0;

Generated with cgit - Back to sebastiano.tronto.net