CTEST2(ccp, bigpart) { idx_t const N = 25000000; idx_t const P = 24; idx_t * weights = malloc(N * sizeof(*weights)); idx_t * parts = malloc((P+1) * sizeof(*weights)); for(idx_t x=0; x < N; ++x) { weights[x] = rand_idx() % 100; } sp_timer_t part; timer_fstart(&part); idx_t const bneck = partition_1d(weights, N, parts, P); timer_stop(&part); /* correctness */ bool success; success = lprobe(weights, N, parts, P, bneck); ASSERT_EQUAL(true, success); success = lprobe(weights, N, parts, P, bneck-1); ASSERT_EQUAL(false, success); free(weights); free(parts); }
int main() { int user_action, my_action; int user_rec[] = {0, 0, 0}; const char *names[] = { "Rock", "Paper", "Scissors" }; char str[2]; const char *winner[] = { "We tied.", "Meself winned.", "You win." }; double p[LEN] = { 1./3, 1./3, 1./3 }; while (1) { my_action = rand_idx(p,LEN); printf("\nYour choice [1-3]:\n" " 1. Rock\n 2. Paper\n 3. Scissors\n> "); /* scanf is a terrible way to do input. should use stty and keystrokes */ if (!scanf("%d", &user_action)) { scanf("%1s", str); if (*str == 'q') { printf("Your choices [rock : %d , paper : %d , scissors %d] ",user_rec[0],user_rec[1], user_rec[2]); return 0; } continue; } user_action --; if (user_action > 2 || user_action < 0) { printf("invalid choice; again\n"); continue; } printf("You chose %s; I chose %s. %s\n", names[user_action], names[my_action], winner[(my_action - user_action + 3) % 3]); user_rec[user_action]++; } }