aboutsummaryrefslogtreecommitdiff
path: root/src/utils.h
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-07-05 22:16:44 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-07-05 22:28:10 +0200
commit66c1c11ec13d362ddfb1b5f6abe8127969c0ad29 (patch)
tree569e7d4e70d63202c05475b0996038b90da168c5 /src/utils.h
parent5fb58d73581256c64d47250c5544d1cbf22f79c3 (diff)
downloadnissy-core-66c1c11ec13d362ddfb1b5f6abe8127969c0ad29.tar.gz
nissy-core-66c1c11ec13d362ddfb1b5f6abe8127969c0ad29.zip
Finished getcube
Diffstat (limited to '')
-rw-r--r--src/utils.h6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/utils.h b/src/utils.h
index 3d35437..021ca75 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -1,3 +1,5 @@
1#define _swap(x, y) do { x ^= y; y ^= x; x ^= y; } while (0)
2
1_static int64_t factorial(int64_t); 3_static int64_t factorial(int64_t);
2_static bool isperm(uint8_t *, int64_t); 4_static bool isperm(uint8_t *, int64_t);
3_static int64_t permtoindex(uint8_t *, int64_t); 5_static int64_t permtoindex(uint8_t *, int64_t);
@@ -138,7 +140,7 @@ digitstosumzero(uint8_t *a, uint8_t n, uint8_t b)
138 return -1; 140 return -1;
139 } 141 }
140 142
141 for (i = 1, ret = 0, p = 1; i < n; i++, p *= (int64_t)b) { 143 for (i = 1, ret = 0, p = 1, sum = 0; i < n; i++, p *= (int64_t)b) {
142 if (a[i] >= b) { 144 if (a[i] >= b) {
143 LOG("Error: digit %" PRIu8 " larger than maximum" 145 LOG("Error: digit %" PRIu8 " larger than maximum"
144 " (b=%" PRIu8 "\n", a[i], b); 146 " (b=%" PRIu8 "\n", a[i], b);
@@ -168,7 +170,7 @@ sumzerotodigits(int64_t d, uint8_t n, uint8_t b, uint8_t *a)
168 goto digitstosumzero_error; 170 goto digitstosumzero_error;
169 } 171 }
170 172
171 for (i = 1; i < n; i++, d /= (int64_t)b) { 173 for (i = 1, sum = 0; i < n; i++, d /= (int64_t)b) {
172 a[i] = (uint8_t)(d % (int64_t)b); 174 a[i] = (uint8_t)(d % (int64_t)b);
173 sum += a[i]; 175 sum += a[i];
174 } 176 }

Generated with cgit - Back to sebastiano.tronto.net