-
Notifications
You must be signed in to change notification settings - Fork 91
Table of Lehmer Codes for Swindler's Gambit
petrak@ edited this page Apr 10, 2022
·
3 revisions
The stack is written left-to-right, bottom-to-top. (So cba
has c
at the bottom, b
in the middle, and a
at the top.)
Code | Permutation |
---|---|
Permuting a
| |
0 | a |
Permuting ba
| |
1 | ab |
Permuting cba
| |
2 | bca |
3 | bac |
4 | acb |
5 | abc |
Permuting dcba
| |
6 | cdba |
7 | cdab |
8 | cbda |
9 | cbad |
10 | cadb |
11 | cabd |
12 | bdca |
13 | bdac |
14 | bcda |
15 | bcad |
16 | badc |
17 | bacd |
18 | adcb |
19 | adbc |
20 | acdb |
21 | acbd |
22 | abdc |
23 | abcd |
Permuting edcba
| |
24 | decba |
25 | decab |
26 | debca |
27 | debac |
28 | deacb |
29 | deabc |
30 | dceba |
31 | dceab |
32 | dcbea |
33 | dcbae |
34 | dcaeb |
35 | dcabe |
36 | dbeca |
37 | dbeac |
38 | dbcea |
39 | dbcae |
40 | dbaec |
41 | dbace |
42 | daecb |
43 | daebc |
44 | daceb |
45 | dacbe |
46 | dabec |
47 | dabce |
48 | cedba |
49 | cedab |
50 | cebda |
51 | cebad |
52 | ceadb |
53 | ceabd |
54 | cdeba |
55 | cdeab |
56 | cdbea |
57 | cdbae |
58 | cdaeb |
59 | cdabe |
60 | cbeda |
61 | cbead |
62 | cbdea |
63 | cbdae |
64 | cbaed |
65 | cbade |
66 | caedb |
67 | caebd |
68 | cadeb |
69 | cadbe |
70 | cabed |
71 | cabde |
72 | bedca |
73 | bedac |
74 | becda |
75 | becad |
76 | beadc |
77 | beacd |
78 | bdeca |
79 | bdeac |
80 | bdcea |
81 | bdcae |
82 | bdaec |
83 | bdace |
84 | bceda |
85 | bcead |
86 | bcdea |
87 | bcdae |
88 | bcaed |
89 | bcade |
90 | baedc |
91 | baecd |
92 | badec |
93 | badce |
94 | baced |
95 | bacde |
96 | aedcb |
97 | aedbc |
98 | aecdb |
99 | aecbd |
100 | aebdc |
101 | aebcd |
102 | adecb |
103 | adebc |
104 | adceb |
105 | adcbe |
106 | adbec |
107 | adbce |
108 | acedb |
109 | acebd |
110 | acdeb |
111 | acdbe |
112 | acbed |
113 | acbde |
114 | abedc |
115 | abecd |
116 | abdec |
117 | abdce |
118 | abced |
119 | abcde |
Permuting fedcba
| |
120 | efdcba |
121 | efdcab |
122 | efdbca |
123 | efdbac |
124 | efdacb |
125 | efdabc |
126 | efcdba |
127 | efcdab |
128 | efcbda |
129 | efcbad |
130 | efcadb |
131 | efcabd |
132 | efbdca |
133 | efbdac |
134 | efbcda |
135 | efbcad |
136 | efbadc |
137 | efbacd |
138 | efadcb |
139 | efadbc |
140 | efacdb |
141 | efacbd |
142 | efabdc |
143 | efabcd |
144 | edfcba |
145 | edfcab |
146 | edfbca |
147 | edfbac |
148 | edfacb |
149 | edfabc |
150 | edcfba |
151 | edcfab |
152 | edcbfa |
153 | edcbaf |
154 | edcafb |
155 | edcabf |
156 | edbfca |
157 | edbfac |
158 | edbcfa |
159 | edbcaf |
160 | edbafc |
161 | edbacf |
162 | edafcb |
163 | edafbc |
164 | edacfb |
165 | edacbf |
166 | edabfc |
167 | edabcf |
168 | ecfdba |
169 | ecfdab |
170 | ecfbda |
171 | ecfbad |
172 | ecfadb |
173 | ecfabd |
174 | ecdfba |
175 | ecdfab |
176 | ecdbfa |
177 | ecdbaf |
178 | ecdafb |
179 | ecdabf |
180 | ecbfda |
181 | ecbfad |
182 | ecbdfa |
183 | ecbdaf |
184 | ecbafd |
185 | ecbadf |
186 | ecafdb |
187 | ecafbd |
188 | ecadfb |
189 | ecadbf |
190 | ecabfd |
191 | ecabdf |
192 | ebfdca |
193 | ebfdac |
194 | ebfcda |
195 | ebfcad |
196 | ebfadc |
197 | ebfacd |
198 | ebdfca |
199 | ebdfac |
200 | ebdcfa |
201 | ebdcaf |
202 | ebdafc |
203 | ebdacf |
204 | ebcfda |
205 | ebcfad |
206 | ebcdfa |
207 | ebcdaf |
208 | ebcafd |
209 | ebcadf |
210 | ebafdc |
211 | ebafcd |
212 | ebadfc |
213 | ebadcf |
214 | ebacfd |
215 | ebacdf |
216 | eafdcb |
217 | eafdbc |
218 | eafcdb |
219 | eafcbd |
220 | eafbdc |
221 | eafbcd |
222 | eadfcb |
223 | eadfbc |
224 | eadcfb |
225 | eadcbf |
226 | eadbfc |
227 | eadbcf |
228 | eacfdb |
229 | eacfbd |
230 | eacdfb |
231 | eacdbf |
232 | eacbfd |
233 | eacbdf |
234 | eabfdc |
235 | eabfcd |
236 | eabdfc |
237 | eabdcf |
238 | eabcfd |
239 | eabcdf |
240 | dfecba |
241 | dfecab |
242 | dfebca |
243 | dfebac |
244 | dfeacb |
245 | dfeabc |
246 | dfceba |
247 | dfceab |
248 | dfcbea |
249 | dfcbae |
250 | dfcaeb |
251 | dfcabe |
252 | dfbeca |
253 | dfbeac |
254 | dfbcea |
255 | dfbcae |
256 | dfbaec |
257 | dfbace |
258 | dfaecb |
259 | dfaebc |
260 | dfaceb |
261 | dfacbe |
262 | dfabec |
263 | dfabce |
264 | defcba |
265 | defcab |
266 | defbca |
267 | defbac |
268 | defacb |
269 | defabc |
270 | decfba |
271 | decfab |
272 | decbfa |
273 | decbaf |
274 | decafb |
275 | decabf |
276 | debfca |
277 | debfac |
278 | debcfa |
279 | debcaf |
280 | debafc |
281 | debacf |
282 | deafcb |
283 | deafbc |
284 | deacfb |
285 | deacbf |
286 | deabfc |
287 | deabcf |
288 | dcfeba |
289 | dcfeab |
290 | dcfbea |
291 | dcfbae |
292 | dcfaeb |
293 | dcfabe |
294 | dcefba |
295 | dcefab |
296 | dcebfa |
297 | dcebaf |
298 | dceafb |
299 | dceabf |
300 | dcbfea |
301 | dcbfae |
302 | dcbefa |
303 | dcbeaf |
304 | dcbafe |
305 | dcbaef |
306 | dcafeb |
307 | dcafbe |
308 | dcaefb |
309 | dcaebf |
310 | dcabfe |
311 | dcabef |
312 | dbfeca |
313 | dbfeac |
314 | dbfcea |
315 | dbfcae |
316 | dbfaec |
317 | dbface |
318 | dbefca |
319 | dbefac |
320 | dbecfa |
321 | dbecaf |
322 | dbeafc |
323 | dbeacf |
324 | dbcfea |
325 | dbcfae |
326 | dbcefa |
327 | dbceaf |
328 | dbcafe |
329 | dbcaef |
330 | dbafec |
331 | dbafce |
332 | dbaefc |
333 | dbaecf |
334 | dbacfe |
335 | dbacef |
336 | dafecb |
337 | dafebc |
338 | dafceb |
339 | dafcbe |
340 | dafbec |
341 | dafbce |
342 | daefcb |
343 | daefbc |
344 | daecfb |
345 | daecbf |
346 | daebfc |
347 | daebcf |
348 | dacfeb |
349 | dacfbe |
350 | dacefb |
351 | dacebf |
352 | dacbfe |
353 | dacbef |
354 | dabfec |
355 | dabfce |
356 | dabefc |
357 | dabecf |
358 | dabcfe |
359 | dabcef |
360 | cfedba |
361 | cfedab |
362 | cfebda |
363 | cfebad |
364 | cfeadb |
365 | cfeabd |
366 | cfdeba |
367 | cfdeab |
368 | cfdbea |
369 | cfdbae |
370 | cfdaeb |
371 | cfdabe |
372 | cfbeda |
373 | cfbead |
374 | cfbdea |
375 | cfbdae |
376 | cfbaed |
377 | cfbade |
378 | cfaedb |
379 | cfaebd |
380 | cfadeb |
381 | cfadbe |
382 | cfabed |
383 | cfabde |
384 | cefdba |
385 | cefdab |
386 | cefbda |
387 | cefbad |
388 | cefadb |
389 | cefabd |
390 | cedfba |
391 | cedfab |
392 | cedbfa |
393 | cedbaf |
394 | cedafb |
395 | cedabf |
396 | cebfda |
397 | cebfad |
398 | cebdfa |
399 | cebdaf |
400 | cebafd |
401 | cebadf |
402 | ceafdb |
403 | ceafbd |
404 | ceadfb |
405 | ceadbf |
406 | ceabfd |
407 | ceabdf |
408 | cdfeba |
409 | cdfeab |
410 | cdfbea |
411 | cdfbae |
412 | cdfaeb |
413 | cdfabe |
414 | cdefba |
415 | cdefab |
416 | cdebfa |
417 | cdebaf |
418 | cdeafb |
419 | cdeabf |
420 | cdbfea |
421 | cdbfae |
422 | cdbefa |
423 | cdbeaf |
424 | cdbafe |
425 | cdbaef |
426 | cdafeb |
427 | cdafbe |
428 | cdaefb |
429 | cdaebf |
430 | cdabfe |
431 | cdabef |
432 | cbfeda |
433 | cbfead |
434 | cbfdea |
435 | cbfdae |
436 | cbfaed |
437 | cbfade |
438 | cbefda |
439 | cbefad |
440 | cbedfa |
441 | cbedaf |
442 | cbeafd |
443 | cbeadf |
444 | cbdfea |
445 | cbdfae |
446 | cbdefa |
447 | cbdeaf |
448 | cbdafe |
449 | cbdaef |
450 | cbafed |
451 | cbafde |
452 | cbaefd |
453 | cbaedf |
454 | cbadfe |
455 | cbadef |
456 | cafedb |
457 | cafebd |
458 | cafdeb |
459 | cafdbe |
460 | cafbed |
461 | cafbde |
462 | caefdb |
463 | caefbd |
464 | caedfb |
465 | caedbf |
466 | caebfd |
467 | caebdf |
468 | cadfeb |
469 | cadfbe |
470 | cadefb |
471 | cadebf |
472 | cadbfe |
473 | cadbef |
474 | cabfed |
475 | cabfde |
476 | cabefd |
477 | cabedf |
478 | cabdfe |
479 | cabdef |
480 | bfedca |
481 | bfedac |
482 | bfecda |
483 | bfecad |
484 | bfeadc |
485 | bfeacd |
486 | bfdeca |
487 | bfdeac |
488 | bfdcea |
489 | bfdcae |
490 | bfdaec |
491 | bfdace |
492 | bfceda |
493 | bfcead |
494 | bfcdea |
495 | bfcdae |
496 | bfcaed |
497 | bfcade |
498 | bfaedc |
499 | bfaecd |
500 | bfadec |
501 | bfadce |
502 | bfaced |
503 | bfacde |
504 | befdca |
505 | befdac |
506 | befcda |
507 | befcad |
508 | befadc |
509 | befacd |
510 | bedfca |
511 | bedfac |
512 | bedcfa |
513 | bedcaf |
514 | bedafc |
515 | bedacf |
516 | becfda |
517 | becfad |
518 | becdfa |
519 | becdaf |
520 | becafd |
521 | becadf |
522 | beafdc |
523 | beafcd |
524 | beadfc |
525 | beadcf |
526 | beacfd |
527 | beacdf |
528 | bdfeca |
529 | bdfeac |
530 | bdfcea |
531 | bdfcae |
532 | bdfaec |
533 | bdface |
534 | bdefca |
535 | bdefac |
536 | bdecfa |
537 | bdecaf |
538 | bdeafc |
539 | bdeacf |
540 | bdcfea |
541 | bdcfae |
542 | bdcefa |
543 | bdceaf |
544 | bdcafe |
545 | bdcaef |
546 | bdafec |
547 | bdafce |
548 | bdaefc |
549 | bdaecf |
550 | bdacfe |
551 | bdacef |
552 | bcfeda |
553 | bcfead |
554 | bcfdea |
555 | bcfdae |
556 | bcfaed |
557 | bcfade |
558 | bcefda |
559 | bcefad |
560 | bcedfa |
561 | bcedaf |
562 | bceafd |
563 | bceadf |
564 | bcdfea |
565 | bcdfae |
566 | bcdefa |
567 | bcdeaf |
568 | bcdafe |
569 | bcdaef |
570 | bcafed |
571 | bcafde |
572 | bcaefd |
573 | bcaedf |
574 | bcadfe |
575 | bcadef |
576 | bafedc |
577 | bafecd |
578 | bafdec |
579 | bafdce |
580 | bafced |
581 | bafcde |
582 | baefdc |
583 | baefcd |
584 | baedfc |
585 | baedcf |
586 | baecfd |
587 | baecdf |
588 | badfec |
589 | badfce |
590 | badefc |
591 | badecf |
592 | badcfe |
593 | badcef |
594 | bacfed |
595 | bacfde |
596 | bacefd |
597 | bacedf |
598 | bacdfe |
599 | bacdef |
600 | afedcb |
601 | afedbc |
602 | afecdb |
603 | afecbd |
604 | afebdc |
605 | afebcd |
606 | afdecb |
607 | afdebc |
608 | afdceb |
609 | afdcbe |
610 | afdbec |
611 | afdbce |
612 | afcedb |
613 | afcebd |
614 | afcdeb |
615 | afcdbe |
616 | afcbed |
617 | afcbde |
618 | afbedc |
619 | afbecd |
620 | afbdec |
621 | afbdce |
622 | afbced |
623 | afbcde |
624 | aefdcb |
625 | aefdbc |
626 | aefcdb |
627 | aefcbd |
628 | aefbdc |
629 | aefbcd |
630 | aedfcb |
631 | aedfbc |
632 | aedcfb |
633 | aedcbf |
634 | aedbfc |
635 | aedbcf |
636 | aecfdb |
637 | aecfbd |
638 | aecdfb |
639 | aecdbf |
640 | aecbfd |
641 | aecbdf |
642 | aebfdc |
643 | aebfcd |
644 | aebdfc |
645 | aebdcf |
646 | aebcfd |
647 | aebcdf |
648 | adfecb |
649 | adfebc |
650 | adfceb |
651 | adfcbe |
652 | adfbec |
653 | adfbce |
654 | adefcb |
655 | adefbc |
656 | adecfb |
657 | adecbf |
658 | adebfc |
659 | adebcf |
660 | adcfeb |
661 | adcfbe |
662 | adcefb |
663 | adcebf |
664 | adcbfe |
665 | adcbef |
666 | adbfec |
667 | adbfce |
668 | adbefc |
669 | adbecf |
670 | adbcfe |
671 | adbcef |
672 | acfedb |
673 | acfebd |
674 | acfdeb |
675 | acfdbe |
676 | acfbed |
677 | acfbde |
678 | acefdb |
679 | acefbd |
680 | acedfb |
681 | acedbf |
682 | acebfd |
683 | acebdf |
684 | acdfeb |
685 | acdfbe |
686 | acdefb |
687 | acdebf |
688 | acdbfe |
689 | acdbef |
690 | acbfed |
691 | acbfde |
692 | acbefd |
693 | acbedf |
694 | acbdfe |
695 | acbdef |
696 | abfedc |
697 | abfecd |
698 | abfdec |
699 | abfdce |
700 | abfced |
701 | abfcde |
702 | abefdc |
703 | abefcd |
704 | abedfc |
705 | abedcf |
706 | abecfd |
707 | abecdf |
708 | abdfec |
709 | abdfce |
710 | abdefc |
711 | abdecf |
712 | abdcfe |
713 | abdcef |
714 | abcfed |
715 | abcfde |
716 | abcefd |
717 | abcedf |
718 | abcdfe |
719 | abcdef |
/** iterator yielding 1, 1, 2, 6, 24, ... */
struct Factorial {
acc: usize, n: usize
}
impl Factorial {
fn new() -> Self { Factorial { acc: 1, n: 1 } }
}
impl Iterator for Factorial {
type Item = usize;
fn next(&mut self) -> Option<usize> {
let val = self.acc;
self.acc *= self.n;
self.n += 1;
Some(val)
}
}
fn factorial(x: usize) -> usize {
if x == 0 {
// sorry. it works better this way in these cases
0
} else {
Factorial::new().nth(x).unwrap()
}
}
/** Fn to take a stack and a value and perform a shuffling of the last few elems */
fn ixed_factorial<T: Clone+std::fmt::Debug>(mut value: usize, stack: &mut [T]) -> Result<(), String> {
let mut strides: Vec<usize> = Factorial::new().take_while(|&x| x <= value).collect();
// want only the last few elems of the stack
if stack.len() < strides.len() {
Err("Manipulating too many elements on the stack!")?
}
let stride_offset = stack.len() - strides.len();
let mut edit_target = &mut stack[stride_offset..];
let mut swap = edit_target.to_vec();
while let Some(divisor) = strides.pop() {
let index = value / divisor;
value %= divisor;
edit_target[0] = swap.remove(index);
edit_target = &mut edit_target[1..];
}
Ok(())
}
fn main() {
let max_len = 6;
let template = {
let mut tmp = ('a'..=(b'a' + max_len as u8) as char).collect::<Vec<char>>();
tmp.reverse();
tmp
};
println!("<table>");
println!("<tr><th>Code</th><th>Permutation</th></tr>");
for x in 1..=max_len {
let len = template.len();
let slice = &template[len - x..];
println!("<tr><th colspan=\"2\">Permuting <code>{}</code></th></tr>", slice.iter().collect::<String>());
let fact = factorial(x);
let prev_fact = factorial(x-1);
for code in prev_fact..fact {
let mut permed = slice.to_owned();
ixed_factorial(code, &mut permed).unwrap();
println!("<tr><td>{}</td> <td><code>{}</code></td></tr>", code, permed.iter().collect::<String>());
}
}
println!("</table>");
}