// board is global / result is for these cell bool isRightSukoku(vector<vector<char> > &board ) //, vector<vector<char> > &result, int row, int col) { vector<char> result; for (int i=0; i< 9; i++) { result.clear(); for (int j=0; j<9; j++) { if (board[i][j] == '.') { //return false; } else result.push_back(board[i][j]); } int x = is_dup(result); if (x==0) return false; } for (int j=0; j< 9; j++) { result.clear(); for (int i=0; i<9; i++) { if (board[i][j] != '.') result.push_back(board[i][j]); } int x = is_dup(result); if (x==0) return false; } for (int i=0; i< 3; i++) { for (int j=0; j<3; j++) { result.clear(); for (int x=i*3; x<i*3+3; x++) { for (int y=j*3; y<j*3+3; y++) { if (board[x][y] != '.') result.push_back(board[x][y]); } } int x = is_dup(result); if (x==0) return false; } } return true; }
static int handle(int s, unsigned char * data, int len, struct sockaddr_in * s_in) { REQUIRE(data != NULL); REQUIRE(s_in != NULL); char buf[2048]; unsigned short * cmd = (unsigned short *) buf; int plen; struct in_addr * addr = &s_in->sin_addr; unsigned short * pid = (unsigned short *) data; /* inet check */ if (len == S_HELLO_LEN && memcmp(data, "sorbo", 5) == 0) { unsigned short * id = (unsigned short *) (data + 5); int x = 2 + 4 + 2; *cmd = htons(S_CMD_INET_CHECK); memcpy(cmd + 1, addr, 4); memcpy(cmd + 1 + 2, id, 2); printf("Inet check by %s %d\n", inet_ntoa(*addr), ntohs(*id)); if (send(s, buf, x, 0) != x) return (1); return (0); } *cmd++ = htons(S_CMD_PACKET); *cmd++ = *pid; plen = len - 2; if (plen < 0) return (0); last_id = ntohs(*pid); if (last_id > 20000) wrap = 1; if (wrap && last_id < 100) { wrap = 0; memset(ids, 0, sizeof(ids)); } printf("Got packet %d %d", last_id, plen); if (is_dup(last_id)) { printf(" (DUP)\n"); return (0); } printf("\n"); *cmd++ = htons(plen); memcpy(cmd, data + 2, plen); plen += 2 + 2 + 2; ALLEGE(plen <= (int) sizeof(buf)); if (send(s, buf, plen, 0) != plen) return (1); return (0); }
static void dump (FILE *f) { int i = 0; int j; int k; int nbytes; int line = 0; u8 *b = (u8 *)Buf; u8 c; size_t n; printf(" 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n"); for (;;) { n = fread(Buf, 1, sizeof(Buf), f); if (!n) return; for (i = 0; i < n; i = k) { nbytes = n < BYTES_PER_LINE ? n : BYTES_PER_LINE; line += 16; k = i; if (is_dup( &b[k], nbytes)) { k += nbytes; continue; } printf("%6x ", line); for (j = 0; (j < BYTES_PER_LINE) && (k < n); j++, k++) { c = b[k]; if (j == 8) putchar(' '); printf(" %2x", c); } for (; j < BYTES_PER_LINE; j++) { printf(" "); } printf(" "); k = i; for (j = 0; (j < BYTES_PER_LINE) && (k < n); j++, k++) { c = b[k]; if (isprint(c)) { putchar(c); } else { putchar('.'); } } putchar('\n'); } } }
/* Generate BUFFER_NUM factorial free orders. */ static void binder_selftest_free_seq(struct binder_alloc *alloc, size_t *sizes, int *seq, int index, size_t end) { int i; if (index == BUFFER_NUM) { binder_selftest_alloc_free(alloc, sizes, seq, end); return; } for (i = 0; i < BUFFER_NUM; i++) { if (is_dup(seq, index, i)) continue; seq[index] = i; binder_selftest_free_seq(alloc, sizes, seq, index + 1, end); } }