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

Generated with cgit - Back to sebastiano.tronto.net