aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO.txt15
-rw-r--r--shell.c4
-rw-r--r--src/cube_generic.h37
-rw-r--r--src/utils.h6
-rw-r--r--test/081_getcube/00_solved_0.in4
-rw-r--r--test/081_getcube/00_solved_0.out1
-rw-r--r--test/081_getcube/02_scrambled.in4
-rw-r--r--test/081_getcube/02_scrambled.out1
-rw-r--r--test/081_getcube/getcube_tests.c29
9 files changed, 69 insertions, 32 deletions
diff --git a/TODO.txt b/TODO.txt
index abcefc8..acfeeb5 100644
--- a/TODO.txt
+++ b/TODO.txt
@@ -1,19 +1,4 @@
1Check stats for all tables using H48stats solver 1Check stats for all tables using H48stats solver
2 - implement getcube
3 x implement stuff in utils.h
4 x implement functions
5 x unit tests for permtoindex and indextoperm
6 x implement digit array to sumzero and inverse
7 x unit tests for digit arra to sumzero
8 x move cubefromarray from cube_io to where needed (cube_generic)
9 - implement in cube_generic
10 x getcube_fix
11 - getcube
12 x permutation
13 - orientation
14 - unit tests
15 x fix in cube_public
16 - test shell
17 - optional: dr states (includes "fix" option) 2 - optional: dr states (includes "fix" option)
18 - implement tool for stats 3 - implement tool for stats
19 - output to file, only write cocsep to stdout 4 - output to file, only write cocsep to stdout
diff --git a/shell.c b/shell.c
index 5706189..11c53c2 100644
--- a/shell.c
+++ b/shell.c
@@ -241,7 +241,7 @@ randomcube_exec(args_t *args)
241 eo = rand64(); 241 eo = rand64();
242 cp = rand64(); 242 cp = rand64();
243 co = rand64(); 243 co = rand64();
244 ret = nissy_getcube(ep, eo, cp, co, args->str_options, result); 244 ret = nissy_getcube(ep, eo, cp, co, "fix", result);
245 print_str_result(ret, result); 245 print_str_result(ret, result);
246 246
247 return ret; 247 return ret;
@@ -305,7 +305,7 @@ gendata_exec(args_t *args)
305 } 305 }
306 if (ret != size) { 306 if (ret != size) {
307 fprintf(stderr, "Unknown error: unexpected data size " 307 fprintf(stderr, "Unknown error: unexpected data size "
308 "got %" PRId64 ", expected %" PRId64)\n", ret, size); 308 "got %" PRId64 ", expected %" PRId64 ")\n", ret, size);
309 fclose(file); 309 fclose(file);
310 free(buf); 310 free(buf);
311 return -5; 311 return -5;
diff --git a/src/cube_generic.h b/src/cube_generic.h
index c40844d..fe36f90 100644
--- a/src/cube_generic.h
+++ b/src/cube_generic.h
@@ -185,34 +185,45 @@ frommoves(const char *buf)
185_static void 185_static void
186getcube_fix(int64_t *ep, int64_t *eo, int64_t *cp, int64_t *co) 186getcube_fix(int64_t *ep, int64_t *eo, int64_t *cp, int64_t *co)
187{ 187{
188 uint8_t e[12], c[8], aux; 188 uint8_t e[12], c[8], coarr[8];
189 189
190 *ep %= _12f; 190 *ep = (*ep % _12f + _12f) % _12f;
191 *eo %= _2p11; 191 *eo = (*eo % _2p11 + _2p11) % _2p11;
192 *cp %= _8f; 192 *cp = (*cp % _8f + _8f) % _8f;
193 *cp %= _3p7; 193 *co = (*cp % _3p7 + _3p7) % _3p7;
194 194
195 indextoperm(*ep, 12, e); 195 indextoperm(*ep, 12, e);
196 indextoperm(*cp, 8, c); 196 indextoperm(*cp, 8, c);
197 if (permsign(e, 12) != permsign(c, 8)) { 197 if (permsign(e, 12) != permsign(c, 8)) {
198 aux = c[0]; 198 _swap(c[0], c[1]);
199 c[0] = c[1];
200 c[1] = aux;
201 *cp = permtoindex(c, 8); 199 *cp = permtoindex(c, 8);
200
201 sumzerotodigits(*co, 8, 3, coarr);
202 _swap(coarr[0], coarr[1]);
203 *co = digitstosumzero(coarr, 8, 3);
202 } 204 }
203} 205}
204 206
205_static cube_t 207_static cube_t
206getcube(int64_t ep, int64_t eo, int64_t cp, int64_t co) 208getcube(int64_t ep, int64_t eo, int64_t cp, int64_t co)
207{ 209{
208 uint8_t e[12], c[8]; 210 uint8_t i, earr[12], carr[8], eoarr[12], coarr[8];
209 211
210 indextoperm(ep, 12, e); 212 sumzerotodigits(eo, 12, 2, eoarr);
211 indextoperm(cp, 8, c); 213 DBG_ASSERT(eoarr[0] != _error, zero, "Error making EO");
214 indextoperm(ep, 12, earr);
215 DBG_ASSERT(earr[0] != _error, zero, "Error making EP");
216 for (i = 0; i < 12; i++)
217 earr[i] |= eoarr[i] << _eoshift;
212 218
213 /* TODO: orientation */ 219 sumzerotodigits(co, 8, 3, coarr);
220 DBG_ASSERT(coarr[0] != _error, zero, "Error making CO");
221 indextoperm(cp, 8, carr);
222 DBG_ASSERT(carr[0] != _error, zero, "Error making CP");
223 for (i = 0; i < 8; i++)
224 carr[i] |= coarr[i] << _coshift;
214 225
215 return cubefromarray(c, e); 226 return cubefromarray(carr, earr);
216} 227}
217 228
218_static cube_t 229_static cube_t
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 }
diff --git a/test/081_getcube/00_solved_0.in b/test/081_getcube/00_solved_0.in
new file mode 100644
index 0000000..44e0be8
--- /dev/null
+++ b/test/081_getcube/00_solved_0.in
@@ -0,0 +1,4 @@
10
20
30
40
diff --git a/test/081_getcube/00_solved_0.out b/test/081_getcube/00_solved_0.out
new file mode 100644
index 0000000..dff224d
--- /dev/null
+++ b/test/081_getcube/00_solved_0.out
@@ -0,0 +1 @@
UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0
diff --git a/test/081_getcube/02_scrambled.in b/test/081_getcube/02_scrambled.in
new file mode 100644
index 0000000..b24bfbf
--- /dev/null
+++ b/test/081_getcube/02_scrambled.in
@@ -0,0 +1,4 @@
1367124500
2450
330807
4562
diff --git a/test/081_getcube/02_scrambled.out b/test/081_getcube/02_scrambled.out
new file mode 100644
index 0000000..6a05bbc
--- /dev/null
+++ b/test/081_getcube/02_scrambled.out
@@ -0,0 +1 @@
FL0 DB0 UB1 FR0 UR0 DF0 UF0 BR1 UL1 BL1 DL0 DR0 DFR1 UFR1 UBR1 UFL2 DBR2 DFL0 DBL2 UBL0
diff --git a/test/081_getcube/getcube_tests.c b/test/081_getcube/getcube_tests.c
new file mode 100644
index 0000000..7eb59dc
--- /dev/null
+++ b/test/081_getcube/getcube_tests.c
@@ -0,0 +1,29 @@
1#include "../test.h"
2
3cube_t getcube(int64_t, int64_t, int64_t, int64_t);
4
5void run(void) {
6 char str[STRLENMAX];
7 cube_t cube;
8 int64_t ep, eo, cp, co;
9
10 fgets(str, STRLENMAX, stdin);
11 ep = atoll(str);
12 fgets(str, STRLENMAX, stdin);
13 eo = atoll(str);
14 fgets(str, STRLENMAX, stdin);
15 cp = atoll(str);
16 fgets(str, STRLENMAX, stdin);
17 co = atoll(str);
18
19 cube = getcube(ep, eo, cp, co);
20
21 if (iserror(cube)) {
22 printf("Error cube\n");
23 } else if (!isconsistent(cube)) {
24 printf("Inconsistent cube\n");
25 } else {
26 writecube("H48", cube, str);
27 printf("%s\n", str);
28 }
29}

Generated with cgit - Back to sebastiano.tronto.net