Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- [2018-06-22] Challenge #364 [Hard] Tiling with Pentominos
- /r/dailyprogrammer https://redd.it/8t4440
- --> NOT A FULL SOLUTION! block flip/rotation experiment. <--
- This totally shouldn't be done this way...
- It actually works but way way too messy!
- Attempted full solution based on this was ugly and failed.
- **/
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct { int mark; int width; int heigth; char flip_rots[9]; char *pattern; } pattern_t;
- pattern_t pats[] = {
- { 'a', 5, 1, "1...5...", "aaaaa" },
- { 'b', 3, 3, "1.......", ".b$bbb$.b" },
- { 'c', 3, 3, "12..56..", ".cc$.c$cc" },
- { 'd', 3, 3, "1234....", "d$d$ddd" },
- { 'e', 3, 3, "1.3.56..", "eee$.e$.e" },
- { 'f', 3, 3, "1234....", "f$ff$.ff" },
- { 'g', 3, 2, "1.3.56..", "ggg$g.g" },
- { 'h', 4, 2, "12345678", "h$hhhh" },
- { 'i', 4, 2, "12345678", "..ii$iii" },
- { 'j', 4, 2, "12345678", "..j$jjjj" },
- { 'k', 3, 3, "12345678", ".k$kkk$..k" },
- { 'l', 2, 3, "12345678", "ll$ll$.l" }
- };
- typedef struct { int done; int x; int y; int startx; int endx; int starty; int endy; int rot; char *cmd; } itr_t;
- itr_t mk_itr(char r, pattern_t pat) {
- itr_t ret;
- int w = pat.width - 1;
- int h = pat.heigth - 1;
- char *c = pat.pattern;
- switch(r) { // d X Y bx ex by ey r c
- case '1' : ret = (itr_t){ 0, 0, 0, 0, w, 0, h, 0, c }; break;
- case '2' : ret = (itr_t){ 0, w, 0, w, 0, 0, h, 0, c }; break;
- case '3' : ret = (itr_t){ 0, 0, h, 0, w, h, 0, 0, c }; break;
- case '4' : ret = (itr_t){ 0, w, h, w, 0, h, 0, 0, c }; break;
- case '5' : ret = (itr_t){ 0, 0, 0, 0, h, 0, w, 1, c }; break;
- case '6' : ret = (itr_t){ 0, 0, w, 0, h, w, 0, 1, c }; break;
- case '7' : ret = (itr_t){ 0, h, 0, h, 0, 0, w, 1, c }; break;
- case '8' : ret = (itr_t){ 0, h, w, h, 0, w, 0, 1, c }; break;
- default : fprintf(stderr, "wrong way! no flip_rots orientation '%c' (0x%02x)\n", r, r);
- exit(1);
- };
- return ret;
- }
- void itr_step(itr_t *it) {
- int dx = (it->endx > it->startx) ? +1 : -1;
- int dy = (it->endy > it->starty) ? +1 : -1;
- if(it->rot) {
- if(*it->cmd == '$') { it->y = it->starty; it->x += dx; }
- else { it->y += dy; }
- }
- else {
- if(*it->cmd == '$') { it->x = it->startx; it->y += dy; }
- else { it->x += dx; }
- }
- if(*it->cmd == '\0') it->done = 1;
- else it->cmd++;
- return;
- }
- int main() {
- int p, r, i, j;
- char a[5][5];
- itr_t it;
- for(p = 0; p < 12; p++) {
- for(r = '1'; r <= '8'; r++) {
- for(i = 0; i < 5; i++) for(j = 0; j < 5; j++) a[i][j] = '.';
- // try our complex iterator...
- it = mk_itr(r, pats[p]);
- for(itr_t it = mk_itr(r, pats[p]); !it.done; itr_step(&it)) {
- if(*it.cmd != '.' && *it.cmd != '$') a[it.x][it.y] = *it.cmd;
- }
- // print the result
- for(j = 0; j < 5; j++) {
- for(i = 0; i < 5; i++) putc(a[i][j], stdout);
- putc('\n', stdout);
- }
- putc('\n', stdout);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement