int main(void) { char str[10] = "abcdefg"; char str_perm[10] = "bacedgf"; char str_not_perm[10] = "gffaecd"; char str_wrong_length[10] = "ab"; char *str_null = NULL; if(is_permutation(str, str)) printf("str, str passed\n"); else printf("str, str failed\n"); if(is_permutation(str, str_perm)) printf("str, str_perm passed\n"); else printf("str, str_perm failed\n"); if(is_permutation(str, str_not_perm)) printf("str, str_not_perm failed\n"); else printf("str, str_not_perm passed\n"); if(is_permutation(str, str_wrong_length)) printf("str, str_wrong_length failed\n"); else printf("str, str_wrong_length passed\n"); if(is_permutation(str, str_null)) printf("str, str_null failed\n"); else printf("str, str_null passed\n"); return EXIT_SUCCESS; }
void test8() { char * str1 = "purude"; char * str2 = "edurpu"; printf("STR1 = %s\n", str1); printf("STR2 = %s\n", str2); int val = is_permutation( str1, str2 ); if ( val ) { printf("Is a permutation\n"); } else { printf("Not a permutation\n"); } printf("\n"); str1 = "abd"; str2 = "cbb"; printf("STR1 = %s\n", str1); printf("STR2 = %s\n", str2); val = is_permutation( str1, str2 ); if ( val ) { printf("Is a permutation\n"); } else { printf("Not a permutation\n"); } }
int main(){ int not_perm[5] = {1, 4, 5, 2, 1}; int perm[5] = { 1, 2, 4, 0, 3}; printf("Permutation check:\n"); printf("%i: ", is_permutation(perm, 5)); print_array(perm, 5); printf("%i: ", is_permutation(not_perm, 5)); print_array(not_perm, 5); return 0; }
gint main() { is_permutation(23145, 23233); return 0; }
int main() { clock_t start, end; float min = SIZE; int result; start = clock(); for(int i = 2; i < SIZE; ++i){ euler[i] = i - 1; } for(int i = 2; i < SIZE; ++i){ int phi = euler[i]; if(is_permutation(i, phi) && i*1.0/phi < min){ min = i*1.0/phi; result = i; } for(int j = 2*i; j < SIZE; j += i){ euler[j] -= euler[i]; } } end = clock(); printf("Result is %d\nRatio is %10.3f\n", result, min); printf("Elasped time: %10.3f seconds.\n", (end-start)*1.0/CLOCKS_PER_SEC ); return EXIT_SUCCESS; }
int main() { unsigned int a,b,c; for (a=1000; a<=3340 /* 10000-3330-3330 */ ; a++) { if (a==1487) continue; b = a+3330; c = b+3330; if (is_prime(a) && is_prime(b) && is_prime(c) && is_permutation(a,b) && is_permutation(b,c)) { std::cout << a << b << c << std::endl; break; } } }
int main (int argc, char ** argv) { if (argc != 2) { fprintf (stderr, "usage: %s <N>\n", argv[0]); return 1; } int N = atoi (argv[1]); if (N < 1) return 1; int lower_limit = power (10, N - 1); int upper_limit = lower_limit * 10 - 1; long multiplier = lower_limit * 10; bool * primes = eratosthenes_sieve (upper_limit + 1); char next_perm[N + 1]; long max = 0; for (int start = lower_limit; start <= upper_limit; start++) { if (!primes[start]) continue; sprintf (next_perm, "%d", start); while (next_permutation (next_perm)) { int next_val = atoi (next_perm); if (!primes[next_val]) continue; int final_val = next_val + next_val - start; if (final_val > upper_limit) continue; if (!primes[final_val]) continue; if (!is_permutation (next_val, final_val)) continue; long seq_val = (((start * multiplier) + next_val) * multiplier) + final_val; if (seq_val > max) max = seq_val; } } printf ("%ld\n", max); free (primes); return 0; }
int main() { bi_initialize(); int i, j; for (i=1000;i<=10000;++i) { if (i==1487) continue; if (!is_prime(i)) continue; for (j=(10000-i)/2; j>0;--j) { if (is_prime(i+j) && is_prime(i+2*j)) { if (is_permutation(i,i+j) && is_permutation(i,i+2*j)) { printf("%d%d%d\n",i,i+j,i+2*j); i = 10000; break; } } } } bi_terminate(); return 0; }
int main() { std::string s1( "aab" ); std::string s2( "abb" ); std::cout << is_permutation( s1, s2 ) << std::endl; std::cout << is_permutation2( s1, s2 ) << std::endl; return 0; }
int main() { char str[1024], str2[1024]; printf("Strings <str1> <str2> :"); scanf("%s%s", str, str2); printf("PERMUTATION : %d\n", is_permutation(str, str2)); return 0; }
int main() { assert(unique1("")); assert(unique1("a")); assert(!unique1("aa")); assert(unique1("asdfjkl;")); assert(!unique1("asdfjkl;a")); assert(unique2("")); assert(unique2("a")); assert(!unique2("aa")); assert(unique2("asdfjkl;")); assert(!unique2("asdfjkl;a")); char s[][10] = {"", "abc", "abcd"}; char r[][10] = {"", "cba", "dcba"}; for (int i = 0; i < 3; i++) { reverse(s[i]); assert(strcmp(s[i], r[i]) == 0); } assert(is_permutation("abcd", "dcba")); assert(!is_permutation("abcd", "ddcba")); }
static bool is_permutation(expr const & lhs, expr const & rhs, unsigned offset, buffer<optional<unsigned>> & p) { if (lhs.kind() != rhs.kind()) return false; switch (lhs.kind()) { case expr_kind::Constant: case expr_kind::Sort: case expr_kind::Meta: case expr_kind::Local: return lhs == rhs; case expr_kind::Var: if (var_idx(lhs) < offset) { return lhs == rhs; // locally bound variable } else if (var_idx(lhs) - offset < p.size()) { if (p[var_idx(lhs) - offset]) { return *(p[var_idx(lhs) - offset]) == var_idx(rhs); } else { p[var_idx(lhs) - offset] = var_idx(rhs); return true; } } else { return lhs == rhs; // free variable } case expr_kind::Lambda: case expr_kind::Pi: return is_permutation(binding_domain(lhs), binding_domain(rhs), offset, p) && is_permutation(binding_body(lhs), binding_body(rhs), offset+1, p); case expr_kind::App: return is_permutation(app_fn(lhs), app_fn(rhs), offset, p) && is_permutation(app_arg(lhs), app_arg(rhs), offset, p); case expr_kind::Macro: if (macro_def(lhs) != macro_def(rhs) || macro_num_args(lhs) != macro_num_args(rhs)) return false; for (unsigned i = 0; i < macro_num_args(lhs); i++) { if (!is_permutation(macro_arg(lhs, i), macro_arg(rhs, i), offset, p)) return false; } return true; } lean_unreachable(); }
void test7() { char * str1 = "hello"; char * str2 = "hole"; printf("STR1 = %s\n", str1); printf("STR2 = %s\n", str2); int val = is_permutation( str1, str2 ); if ( val ) { printf("Is a permutation\n"); } else { printf("Not a permutation\n"); } }
void test6() { char * str1 = "coral"; char * str2 = "laroc"; printf("STR1 = %s\n", str1); printf("STR2 = %s\n", str2); int val = is_permutation( str1, str2 ); if ( val ) { printf("Is a permutation\n"); } else { printf("Not a permutation\n"); } }
int main(void){ int n = 0, m = 0, f = 0; int i = 0; unsigned long number1 = 4778, number2 = 8477; n = is_permutation(number1,number2); for(i = 100; i < 1000000 ; i++){ if(is_staggering(i) == 0){ m++; } } f = is_permutation_nostring(number1,number2); printf("%d\n%d\n%d\n",n,m,f); return 0; }
std::vector<uint> Tours::startingtime_permutation() const{ std::vector<uint> perm; auto jobs = all_jobs(); std::sort(begin(jobs), end(jobs), [](const scheduledJob &a,const scheduledJob &b){ return std::get<1>(a) < std::get<1>(b); } ); for(auto j: jobs) perm.push_back(std::get<0>(j)->num() - 1); assert( is_permutation(perm) ); return perm; }
bool is_permutation_ceqv(environment const & env, expr e) { unsigned num_args = 0; while (is_pi(e)) { e = binding_body(e); num_args++; } expr lhs, rhs; if (is_simp_relation(env, e, lhs, rhs)) { buffer<optional<unsigned>> permutation; permutation.resize(num_args); return is_permutation(lhs, rhs, 0, permutation); } else { return false; } }
int main(void) { unsigned long n1 = 743526; unsigned long n2 = 237654; unsigned long n3 = 743526; unsigned long n4 = 123765; unsigned long n5 = 66666; unsigned long n6 = 144358; unsigned long myN = 0; int myCount = 0; printf("%d\n", is_permutation(n1, n2) == 1); printf("%d\n\n", is_permutation_no_strings(n1, n2) == 1); printf("%d\n", is_permutation(n3, n4) == 0); printf("%d\n\n", is_permutation_no_strings(n3, n4) == 0); printf("%d\n", is_staggering(n5) == 1); printf("%d\n", is_staggering(n6) == 1); printf("%d\n", is_staggering(n1) == 0); for(myN = 100; myN < 1000000; myN++) { if(is_staggering(myN) == 0) { myCount++; } } printf("%d", myCount+100); return 0; }
int main() { clock_t start, end; const int range = 10000000; float min = range; int result; start = clock(); for(int i = 2; i < range; ++i){ int phi = euler(i); if(is_permutation(i, phi) && i*1.0/phi < min){ min = i*1.0/phi; result = i; } } end = clock(); printf("Result is %d\nRatio is %10.3f\n", result, min); printf("Elasped time: %10.3f seconds.\n", (end-start)*1.0/CLOCKS_PER_SEC ); return EXIT_SUCCESS; }
int main(int argc, char const* argv[]) { char s[] = "HelloWorld"; char n1[] = "foobar"; char n2[] = "HelloWorlp"; char n3[] = ""; char o1[] = "edlHWollor"; char o2[] = "oWoerlldHl"; char o3[] = "HlroodleWl"; assert(is_permutation(s, n1) == 0); assert(is_permutation(s, n2) == 0); assert(is_permutation(s, n3) == 0); assert(is_permutation(s, o1) == 1); assert(is_permutation(s, o2) == 1); assert(is_permutation(s, o3) == 1); return 0; }