void test_check_base() { //TODO : Tester qu'il n'y a pas 2 fois le même caractère dans la base test(check_base("0") == 0); test(check_base("01")); test(check_base("11") == 0); test(check_base("ABCDEFGA") == 0); }
int traceVM(int i, int j) { int done; int h; int A_temp; int eVM = 0; done = 0; int VMij = VM(i,j); for (h = i + 2; h <= j - 1 && !done; h++) { A_temp = WM(i+1,h-1) + WM(h,j - 1) + Ea + Eb + auPenalty(i, j); if (A_temp == VMij) { done = 1; eVM += traceWM(i + 1, h - 1); eVM += traceWM(h, j - 1); break; } } if (check_base(i+1)) { for (h = i + 3; h <= j - 1 && !done; h++) { A_temp = WM(i + 2,h - 1) + WM(h,j - 1) + Ea + Eb + auPenalty(i,j) + Ed5(i,j,i + 1); if (A_temp == VMij) { done = 1; eVM += traceWM(i + 2, h - 1); eVM += traceWM(h, j - 1); break; } } } if (check_base(j-1)) { for (h = i + 2; h <= j - 2 && !done; h++) { A_temp = WM(i + 1,h - 1) + WM(h,j - 2) + Ea + Eb + auPenalty(i, j) + Ed3(i,j,j - 1); if (A_temp == VMij) { done = 1; eVM += traceWM(i + 1, h - 1); eVM += traceWM(h, j - 2); break; } } } if (check_base(i+1)&&check_base(j-1)) { for (h = i + 3; h <= j - 2 && !done; h++) { A_temp = WM(i + 2,h - 1) + WM(h,j - 2) + Ea + Eb + auPenalty(i,j) + Ed5(i,j,i + 1) + Ed3(i,j,j - 1); if (A_temp == VMij) { done = 1; eVM += traceWM(i + 2, h - 1); eVM += traceWM(h, j - 2); break; } } } return eVM; }
int traceWM(int i, int j) { int done; int h1, h; int eWM = 0; done = 0; h1 = 0; if (i >= j) return 0; else { for (h = i; h < j && !done; h++) { int aa = WM(i,h) + WM(h + 1,j); if (aa == WM(i,j)) { done = 1; h1 = h; break; } } if (h1 != 0) { eWM += traceWM(i, h); eWM += traceWM(h + 1, j); } else { if (WM(i,j) == V(i,j) + auPenalty(i, j) + Eb) { done = 1; structure[i] = j; structure[j] = i; eWM += traceV(i, j); } else if (WM(i,j) == V(i+1, j) + Ed3(j,i + 1,i) + auPenalty(i+1, j) + Eb + Ec && check_base(i)) { done = 1; eWM += traceV(i + 1, j); structure[i + 1] = j; structure[j] = i + 1; } else if (WM(i,j) == V(i,j-1) + Ed5(j-1,i,j) + auPenalty(i,j-1) + Eb + Ec && check_base(j) ) { done = 1; eWM += traceV(i, j - 1); structure[i] = j - 1; structure[j - 1] = i; } else if (WM(i,j) == V(i+1,j-1) + Ed3(j-1,i+1,i) + Ed5(j-1,i+1,j) + auPenalty(i+1, j-1) + Eb + 2*Ec && check_base(i) && check_base(j)) { done = 1; eWM += traceV(i + 1, j - 1); structure[i + 1] = j - 1; structure[j - 1] = i + 1; } else if (WM(i,j) == WM(i + 1,j) + Ec && check_base(i)) { done = 1; eWM += traceWM(i + 1, j); } else if (WM(i,j) == WM(i,j - 1) + Ec && check_base(j)) { done = 1; eWM += traceWM(i, j - 1); } } } return eWM; }
int my_getnbr_base(char *str, char *base) { int nbr; int len; int j; int k; int i; len = init(base, &nbr, &j, &i); i = check_neg(str); if (check_base(base, 0) == -1) { return (0); } while (str[j]) { k = 0; while (k < len && base[k] != str[j]) k = k + 1; if (base[k] == str[j]) nbr = nbr * len + k; else if ((str[j] != '-' && str[j] != '+')) return (0); j = j + 1; } return (nbr * i); }
int my_getchar(char *str, char *base, int *k, t_mytok flag) { int letter; int i; letter = 0; while (check_base(str[*k], base) != (int)flag) ++(*k); i = *k; while (check_base(str[i], base) == (int)flag && str[i] != '\0') { ++i; ++letter; } return (letter); }
unsigned long int ft_putunslongint_base(unsigned long int n, char *base) { char c; int len_base; int i; i = 1; len_base = ft_strlen_printf(base); if (check_base(base) == 1) { if (n / len_base > 0) { i += ft_putunslongint_base(n / len_base, base); ft_putunslongint_base(n % len_base, base); } else { c = base[n]; write(1, &c, 1); } return (i); } else return (ft_putlongnbr(n)); }
int main(int argc, char **argv) { char *msg; int key[4]; int flag; int *res; size_t msg_len; if (argc == 8) { flag = atoi(argv[7]); if (check_base(argv[6])) { if ((flag == 0 && (msg = check_msg(argv[1]))) || (flag == 1 && (msg = check_msg_base(argv[1], argv[6])))) { if (get_key(argv[2], argv[3], argv[4], argv[5], key)) { if (flag == 1) inv_key(key); res = cypher(msg, key, flag, argv[6], &msg_len); if (flag) inv_key(key); print_msg(argv[1], key, argv[6], res, flag, msg_len); free(res); return (0); } } } printf("Invalid args\n"); } else usage(); return (0); }
int my_getnbr_base(char *str, char *base) { int result; int i; int len; char sign; i = 0; result = 0; sign ='+'; if (str && base) { len = my_strlen(base); check_sign(str, len, base); if (str[i] == '-' || str[i] == '+') sign = sign_base(str, &i); if (check_base(str[i], base) == -1) return (-1); result = calc_nbr(str, i, base, len); if (sign == '-') result = -result; return (result); } else return (-1); }
int my_getword(char *str, char *base, t_mytok flag) { int i; int word; i = -1; word = 0; while (str && str[++i]) { if (i == 0 && check_base(str[i], base) == (int)flag) ++word; if (i > 0 && (check_base(str[i], base) == (int)flag && check_base(str[i - 1], base) != (int)flag)) ++word; } return (word); }
void addentry_crs(pcrs A, index i, index j, real entry) { index ii; check_base(i); check_base(j); assert(i<A->numr+INDEX_BASE); assert(j<A->numc+INDEX_BASE); for (ii=A->rowptr[i-INDEX_BASE]; ii<A->rowptr[i-INDEX_BASE+1]; ++ii) { if (A->colind[ii]==j) { A->vals[ii] += entry; return; } } fprintf(stderr, "Index not in range of sparse matrix\n"); }
char check_sign(char *str, int len, char *base) { int i; i = 0; while (str && str[i] && (str[i] == '+' || str[i] == '-')) i++; while (str && str[i] && check_base(str[i], base) >= 0) i++; if (i > 10) exit(EXIT_FAILURE); }
real getentry_crs(pccrs A, index i, index j) { index ii; real entry; check_base(i); check_base(j); assert(i<A->numr+INDEX_BASE); assert(j<A->numc+INDEX_BASE); entry = 0.; for (ii=A->rowptr[i-INDEX_BASE]; ii<A->rowptr[i-INDEX_BASE+1]; ++ii) { if (A->colind[ii]==j) { entry = A->vals[ii]; } } return entry; }
int calc_nbr(char *str, int i, char *base, int len) { int i_base; int result; int exp; int j; exp = 0; result = 0; j = i; while (str && str[j + 1] && check_base(str[j + 1], base) != -1) j++; while (str && str[j] && j >= i) { if (214783647 - result <= my_power_rec(len, exp)) exit(3); i_base = check_base(str[j], base); result = result + (i_base * my_power_rec(len, exp)); j--; exp++; } return (result); }
int is_valid(char *base, char *ops) { int base_len; char dup[256]; my_bzero(dup, 256); if ((base_len = check_base(base, dup)) < 2) { if (!base_len) { my_putstr("Providing twice the same character in the base string is \ nonsense.\n"); return (0); } }
int main(int ac, char **av) { char *expr; unsigned int size; char *final; if (ac != 4) { my_putstr("Usage : "); my_putstr(av[0]); my_putstr(" base ops\"()+-*/%\" exp_len\n"); exit(1); } check_base(av[1]); check_ops(av[2]); size = my_atoi(av[3]); expr = get_expr(size); final = eval_expr(av[1], av[2], expr, size);
char *treat_o(char *str) { const char *padd; padd = ((g_trait & OPT_ZERO) == OPT_ZERO) ? "0" : " "; if ((g_trait & OPT_DIESE) == OPT_DIESE && check_base(str, 8) != 0) g_precision = (ft_strlen(str) >= g_precision) ? ft_strlen(str) + 1 : g_precision; while (ft_strlen(str) < g_precision) str = complete(str, 1, "0"); while (ft_strlen(str) < g_width) { if ((g_trait & OPT_MIN) == OPT_MIN) str = complete_behind(str, 2, " "); else str = complete(str, 1, padd); } return (str); }
char *my_putword(char *str, char *base, int *k, t_mytok flag) { char *word; int len; int i; i = 0; len = my_getchar(str, base, k, flag) + 1; if ((word = malloc(len * sizeof(*word))) == NULL) return (NULL); while (check_base(str[*k], base) == (int)flag && str[*k] != '\0') { word[i] = str[*k]; ++i; ++(*k); } word[i] = '\0'; return (word); }
/* ** Main function. Given by the subject. ** When you use this program to compute very large numbers, use the -p ** parramater to enable progress bar display. ** Ex : ./calc "01" "()+-x/%" 999999999 -p */ int main(int ac, char **av) { unsigned int size; char *expr; int p; p = 0; if (ac != 4 && ac != 5) { my_putstr("Usage : "); my_putstr(av[0]); my_putstr(" base (\"0123456789\") ops (\"()+-*/%\") exp_len\n"); exit(1); } else if (ac == 5 && strcmp(av[4], "-p") == 0) p = 1; check_base(av[1]); check_ops(av[2]); size = my_atoi(av[3]); expr = get_expr(size); eval_expr(av[1], av[2], expr, size, p); free(expr); exit(0); }
int main(int ac, char **av) { char *expr; unsigned int size; if (ac != 4) { my_putstr("Usage : "); my_putstr(av[0]); my_putstr(" base ops\"()+-*/%\" exp_len\n"); return (0); } if (check_base(av[1]) == 1) return (0); if (check_ops(av[2]) == 1) return (0); size = my_atoi(av[3]); expr = get_expr(size); if (expr == NULL) return (0); my_putstr(eval_expr(av[1], av[2], expr, size)); my_putstr("\n"); return (0); }
void traceW(int j) { int done, i, Wj,Wj_temp; int wim1, flag, Widjd, Wijd, Widj, Wij; Wj = INFINITY_; flag = 1; done = 0; if (j == 0 || j == 1) return; for (i = 1; i < j && !done; i++) { if (j-i < TURN) continue; wim1 = MIN(0, W[i-1]); flag = 1; if (wim1 != W[i-1]) flag = 0; Widjd = Wijd = Widj = INFINITY_; Wij = V(i,j) + auPenalty(i, j) + wim1; Widjd =(check_base(i)&&check_base(j))?(V(i+1,j-1) + auPenalty(i+1, j-1) + Ed3(j-1,i+1,i) + Ed5(j-1,i+1,j) + wim1): INFINITY_; Wijd = (check_base(j))?(V(i,j-1) + auPenalty(i,j-1) + Ed5(j-1,i,j) + wim1):INFINITY_; Widj = (check_base(i))?(V(i+1,j) + auPenalty(i+1,j) + Ed3(j,i+1,i) + wim1):INFINITY_; Wj_temp=Wj; Wj = MIN(MIN(MIN(Wij, Widjd), MIN(Wijd, Widj)), Wj); if (W[j] == Wj) { if (W[j] == Wij) { done = 1; if (verbose == 1) printf("i %5d j %5d ExtLoop %12.2f\n", i, j, auPenalty(i, j)/100.00); total_ex += auPenalty(i, j); structure[i] = j; structure[j] = i; traceV(i, j); if (flag || is_ss(1,i)) traceW(i - 1); break; } else if (W[j] == Widjd && check_base(i) && check_base(j)) { done = 1; if (verbose == 1) printf("i %5d j %5d ExtLoop %12.2f\n", i+1, j-1, (auPenalty(i+1, j-1) + Ed3(j-1,i+1,i) + Ed5(j-1,i+1,j))/100.00); total_ex += (auPenalty(i+1, j-1) + Ed3(j-1,i+1,i) + Ed5(j-1,i+1,j)); structure[i + 1] = j - 1; structure[j - 1] = i + 1; traceV(i + 1, j - 1); if (flag || is_ss(1,i)) traceW(i - 1); break; } else if (W[j] == Wijd && check_base(j)) { done = 1; if (verbose == 1) printf("i %5d j %5d ExtLoop %12.2f\n", i, j-1, (auPenalty(i,j-1) + Ed5(j-1,i,j))/100.00); total_ex += (auPenalty(i,j-1) + Ed5(j-1,i,j)); structure[i] = j - 1; structure[j - 1] = i; traceV(i, j - 1); if (flag || is_ss(1,i)) traceW(i - 1); break; } else if (W[j] == Widj && check_base(i)) { done = 1; if (verbose == 1) printf("i %5d j %5d ExtLoop %12.2f\n", i+1, j, (auPenalty(i+1,j) + Ed3(j,i+1,i))/100.00); total_ex += (auPenalty(i+1,j) + Ed3(j,i+1,i)); structure[i + 1] = j; structure[j] = i + 1; traceV(i + 1, j); if (flag || is_ss(1,i)) traceW(i - 1); break; } } } if (W[j] == W[j - 1] && !done) traceW(j-1); return; }
bool check (const Geometry& geo, Treelog& msg) const { return check_base (geo, msg); }
void check_various (void) { static const struct { const char *base; } data[] = { { "0" }, { "1" }, { "2" }, { "3" }, { "4" }, { "5" }, { "6" }, { "10" }, { "15" }, { "16" }, { "0x1F" }, { "0xFF" }, { "0x1001" }, { "0xFFFF" }, { "0x10000001" }, { "0x1000000000000001" }, /* actual size closest to estimate */ { "0xFFFFFFFF" }, { "0xFFFFFFFFFFFFFFFF" }, /* same after rshift */ { "0xFFFFFFFF0" }, { "0xFFFFFFFF00" }, { "0xFFFFFFFFFFFFFFFF0" }, { "0xFFFFFFFFFFFFFFFF00" }, /* change from 2 limbs to 1 after rshift */ { "0x180000000" }, { "0x18000000000000000" }, /* change from 3 limbs to 2 after rshift */ { "0x18000000100000000" }, { "0x180000000000000010000000000000000" }, /* handling of absolute value */ { "-0x80000000" }, { "-0x8000000000000000" }, /* low zero limb, and size>2, checking argument overlap detection */ { "0x3000000000000000300000000000000030000000000000000" }, }; mpz_t base; int i; mpz_init (base); for (i = 0; i < numberof (data); i++) { mpz_set_str_or_abort (base, data[i].base, 0); check_base (base); } mpz_clear (base); }