Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <pthread.h>
- /*
- IPQkm
- XhUjv
- SogLr
- YNtfW
- abcdE
- */
- #define THREADS 6
- #define CONDITION_START(a, A, B, C, D) a = 65 - A - B - C - D; if (used[a] == 0) { used[a] = 1;
- #define LOOP_START(a) for (a = 1; a <= 25; a++) { if (used[a]) continue; used[a] = 1;
- #define END(a) used[a] = 0; }
- int compute(int startValue) {
- int usedArray[200];
- int *used = usedArray + 100;
- for (int i = -100; i < 100; i++)
- used[i] = (i >= 1 && i <= 25) ? 0 : 1;
- int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y;
- a=b=c=d=e=f=g=h=i=j=k=l=m=n=o=p=q=r=s=t=u=v=w=x=y=0;
- int count = 0;
- LOOP_START(a)
- for (b = startValue; b <= 25; b += THREADS) { if (used[b]) continue; used[b] = 1;
- LOOP_START(c)
- LOOP_START(d)
- CONDITION_START(e, a, b, c, d)
- if (e < a) {
- used[e] = 0;
- used[d] = 0;
- continue;
- }
- LOOP_START(f)
- LOOP_START(g)
- LOOP_START(h)
- CONDITION_START(i, h, g, f, e)
- if (i < a || i < e) {
- used[i] = 0;
- used[h] = 0;
- continue;
- }
- LOOP_START(j)
- LOOP_START(k)
- CONDITION_START(l, k, j, f, d)
- LOOP_START(m)
- if (m < a) {
- used[m] = 0;
- continue;
- }
- CONDITION_START(n, a, g, j, m)
- LOOP_START(o)
- CONDITION_START(p, h, o, n, b)
- CONDITION_START(q, i, p, k, m)
- LOOP_START(r)
- CONDITION_START(s, o, g, l, r)
- LOOP_START(t)
- CONDITION_START(u, q, g, t, c)
- LOOP_START(v)
- CONDITION_START(w, m, v, r, e)
- CONDITION_START(x, h, u, j, v)
- y = 65 - i - x - s - a;
- count++;
- END(x)
- END(w)
- END(v)
- END(u)
- END(t)
- END(s)
- END(r)
- END(q)
- END(p)
- END(o)
- END(n)
- END(m)
- END(l)
- END(k)
- END(j)
- END(i)
- END(h)
- END(g)
- END(f)
- END(e)
- END(d)
- END(c)
- END(b)
- END(a)
- count *= 8;
- return count;
- }
- void *threadFunc(void *argument) {
- int threadId = *((int*)argument);
- int *result = calloc(1, sizeof(int));
- *result = compute(threadId + 1);
- return result;
- }
- int main() {
- int arguments[THREADS];
- pthread_t threads[THREADS];
- int *results[THREADS];
- for (int i = 0; i < THREADS; i++)
- arguments[i] = i;
- for (int i = 0; i < THREADS; i++)
- pthread_create(&threads[i], NULL, threadFunc, &arguments[i]);
- for (int i = 0; i < THREADS; i++)
- pthread_join(threads[i], (void **)&results[i]);
- int count = 0;
- for (int i = 0; i < THREADS; i++) {
- count += *results[i];
- free(results[i]);
- }
- printf("%u\n", (unsigned)count);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement