Movatterモバイル変換


[0]ホーム

URL:


Sorry, we no longer support your browser
Please upgrade toMicrosoft Edge,Google Chrome, orFirefox. Learn more about ourbrowser support.
Skip to main content

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities includingStack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Loading…
Code Golf

Return to Answer

added 9 characters in body

C (gcc),715685632627620620 614 bytes

#define y(x);}x(l,n,l)int*l;{#define P;printf(u,v=11,h[5],a[99],b[99],A,B,i,j,k,I,J,K,c,d;oK;o(n){P"%c%c%d","FWS"[n/u],"ROYGBP"[n/v%6],n%v+2)y(O)for(i=0 P i<n?","+!i:" \n")-2;)o(l[i++])y(R)k=n?R(l+1,n-1,l+1),k^*l?k:-1:rand()%198;}r(n){for(h[n]=-1;R(h,5,h),h[n]<0;h[n]=k)u=66 y(z)for(i=n;i--;)for(I=l[j=i]/v;J=l[j]/v,K=l[n-1]/v,j++<n;u*=I%6==J%6|I%6==K%6|J%6==K%6||c|d&&!c|c==d|!dj++<n;)c=Iu*=I%6==J%6|I%6==K%6|J%6==K%6||(K=K/6-J/6,d=K)|(J=I/6-J/6;6)&&!J|J==K|!K;}main(w){for(srand(&w);i<5;)r(i++);for(;u;z(b,B,b)){j=h[J=getchar()-49];RR(0,0);K=j%v)-49];K=j%v-k%v;I=j/u^k/u?j/u-(k/u+2)%3?1:-1:(K>0)-(K<0);O(a,A,a);O(b,B,b);O(h,5,h)P"%d\n",J+1);o(j)P"\n");o(k)P"\n%d\n",I);I>0?a[A++]=j:I?b[B++]=k:0;r(J);z(a,A,a);}}

Try it online!Try it online!

-53-58-65 -6571 bytes thanks to ceilingcat, really nice :)

C (gcc),715685632627620 bytes

#define y(x);}x(l,n)int*l;{#define P;printf(u,v=11,h[5],a[99],b[99],A,B,i,j,k,I,J,K,c,d;o(n){P"%c%c%d","FWS"[n/u],"ROYGBP"[n/v%6],n%v+2)y(O)for(i=0 P i<n?","+!i:" \n")-2;)o(l[i++])y(R)k=n?R(l+1,n-1),k^*l?k:-1:rand()%198;}r(n){for(h[n]=-1;R(h,5),h[n]<0;h[n]=k)u=66 y(z)for(i=n;i--;)for(I=l[j=i]/v;J=l[j]/v,K=l[n-1]/v,j++<n;u*=I%6==J%6|I%6==K%6|J%6==K%6||c|d&&!c|c==d|!d)c=I/6-J/6,d=K/6-J/6;}main(w){for(srand(&w);i<5;)r(i++);for(;u;z(b,B)){j=h[J=getchar()-49];R(0,0);K=j%v-k%v;I=j/u^k/u?j/u-(k/u+2)%3?1:-1:(K>0)-(K<0);O(a,A);O(b,B);O(h,5)P"%d\n",J+1);o(j)P"\n");o(k)P"\n%d\n",I);I>0?a[A++]=j:I?b[B++]=k:0;r(J);z(a,A);}}

Try it online!

-53-58 -65 bytes thanks to ceilingcat, really nice :)

C (gcc),715685632627620 614 bytes

#define y(x);}x(n,l)int*l;{#define P;printf(u,v=11,h[5],a[99],b[99],A,B,i,j,k,I,J,K;o(n){P"%c%c%d","FWS"[n/u],"ROYGBP"[n/v%6],n%v+2)y(O)for(i=0 P i<n?","+!i:" \n")-2;)o(l[i++])y(R)k=n?R(n-1,l+1),k^*l?k:-1:rand()%198;}r(n){for(h[n]=-1;R(5,h),h[n]<0;h[n]=k)u=66 y(z)for(i=n;i--;)for(I=l[j=i]/v;J=l[j]/v,K=l[n-1]/v,j++<n;)u*=I%6==J%6|I%6==K%6|J%6==K%6||(K=K/6-J/6)|(J=I/6-J/6)&&!J|J==K|!K;}main(w){for(srand(&w);i<5;)r(i++);for(;u;z(B,b)){j=h[J=getchar(R(0))-49];K=j%v-k%v;I=j/u^k/u?j/u-(k/u+2)%3?1:-1:(K>0)-(K<0);O(A,a);O(B,b);O(5,h)P"%d\n",J+1);o(j)P"\n");o(k)P"\n%d\n",I);I>0?a[A++]=j:I?b[B++]=k:0;r(J);z(A,a);}}

Try it online!

-53-58-65 -71 bytes thanks to ceilingcat, really nice :)

added 18 characters in body

C (gcc),715685632627627 620 bytes

#define y(x);}x(l,n)int*l;{#define P;printf(u,v=11,h[5],a[99],b[99],A,B,i,j,k,I,J,K,c,d;o(n){P"%c%c%d","FWS"[n/u],"ROYGBP"[n/v%6],n%v+2)y(O){for(i=0 P i<n?","+!i:"\n"" \n"),i<n;-2;)o(l[i++])y(R){k=n?R(l+1,n-1),k^*l?k:-1:rand()%198;}r(n){for(h[n]=-1;R(h,5),h[n]<0;h[n]=k)u=66 y(z){for(i=0;I=l[i]/v,i<n;i=n;i--;)for(j=i++;J=l[j]I=l[j=i]/v;J=l[j]/v,K=l[n-1]/v,j++<n;u*=I%6==J%6|I%6==K%6|J%6==K%6||c|d&&!c|c==d|!d)c=I/6-J/6,d=K/6-J/6;}main(w){for(srand(&w);i<5;)r(i++);for(;u;z(b,B)){j=h[J=getchar()-49];R(0,0);K=j%v-k%v;I=j/u^k/u?j/u-(k/u+2)%3?1:-1:(K>0)-(K<0);O(a,A);O(b,B);O(h,5)P"%d\n",J+1);o(j)P"\n");o(k)P"\n%d\n",I);I>0?a[A++]=j:I?b[B++]=k:0;r(J);z(a,A);}}

Try it online!Try it online!

-53-58 -5865 bytes thanks to ceilingcat, really nice :)

This C version was written in order to check that the challenge was able to be solved even without using a modern programming language. This was pretty fun to make actually, since it was my first answer written in C. This answer was originally posted in order to announce a bounty for the first sub 500-bytes answer (Awarded to Arnauld for his JavaScript anwser).

A small explanation of this code:

  • u andv are constants (u is also used as the checking boolean at the end of a round in order to check if the game is finished)
  • h is the hand (5 cards chosen randomly withr()),a andb are the winning piles for Player 1 and 2,A andB are the number of cards in each pile, and the other variables are used as temporary values
  • o() prints a single card,O() prints a list of cards,R() generates a random card and checks recursively if the card is contained within l, adds -1 to the list otherwise,r() chooses a new random card for the hand, added at position n, by usingR() until the value is a positive number, andz() modifiesu if the game is finished
  • The main program retrieves the two cards chosen by each player, calculates the winner for this round, prints the required lines, adds a new card to the hand, and checks if the game is finished using botha andb

C (gcc),715685632627 bytes

#define y(x);}x(l,n)int*l;#define P;printf(u,v=11,h[5],a[99],b[99],A,B,i,j,k,I,J,K,c,d;o(n){P"%c%c%d","FWS"[n/u],"ROYGBP"[n/v%6],n%v+2)y(O){for(i=0 P i<n?","+!i:"\n"),i<n;)o(l[i++])y(R){k=n?R(l+1,n-1),k^*l?k:-1:rand()%198;}r(n){for(h[n]=-1;R(h,5),h[n]<0;h[n]=k)u=66 y(z){for(i=0;I=l[i]/v,i<n;)for(j=i++;J=l[j]/v,K=l[n-1]/v,j++<n;u*=I%6==J%6|I%6==K%6|J%6==K%6||c|d&&!c|c==d|!d)c=I/6-J/6,d=K/6-J/6;}main(w){for(srand(&w);i<5;)r(i++);for(;u;z(b,B)){j=h[J=getchar()-49];R(0,0);K=j%v-k%v;I=j/u^k/u?j/u-(k/u+2)%3?1:-1:(K>0)-(K<0);O(a,A);O(b,B);O(h,5)P"%d\n",J+1);o(j)P"\n");o(k)P"\n%d\n",I);I>0?a[A++]=j:I?b[B++]=k:0;r(J);z(a,A);}}

Try it online!

-53 -58 bytes thanks to ceilingcat, really nice :)

This C version was written in order to check that the challenge was able to be solved even without using a modern programming language. This was pretty fun to make actually, since it was my first answer written in C. This answer was originally posted in order to announce a bounty for the first sub 500-bytes answer (Awarded to Arnauld for his JavaScript anwser).

A small explanation of this code:

  • u andv are constants (u is also used as the checking boolean at the end of a round in order to check if the game is finished)
  • h is the hand (5 cards chosen randomly withr()),a andb are the winning piles for Player 1 and 2,A andB are the number of cards in each pile, and the other variables are used as temporary values
  • o() prints a single card,O() prints a list of cards,R() generates a random card and checks recursively if the card is contained within l, adds -1 to the list otherwise,r() chooses a new random card for the hand, added at position n, by usingR() until the value is a positive number, andz() modifiesu if the game is finished
  • The main program retrieves the two cards chosen by each player, calculates the winner for this round, prints the required lines, adds a new card to the hand, and checks if the game is finished using botha andb

C (gcc),715685632627 620 bytes

#define y(x);}x(l,n)int*l;{#define P;printf(u,v=11,h[5],a[99],b[99],A,B,i,j,k,I,J,K,c,d;o(n){P"%c%c%d","FWS"[n/u],"ROYGBP"[n/v%6],n%v+2)y(O)for(i=0 P i<n?","+!i:" \n")-2;)o(l[i++])y(R)k=n?R(l+1,n-1),k^*l?k:-1:rand()%198;}r(n){for(h[n]=-1;R(h,5),h[n]<0;h[n]=k)u=66 y(z)for(i=n;i--;)for(I=l[j=i]/v;J=l[j]/v,K=l[n-1]/v,j++<n;u*=I%6==J%6|I%6==K%6|J%6==K%6||c|d&&!c|c==d|!d)c=I/6-J/6,d=K/6-J/6;}main(w){for(srand(&w);i<5;)r(i++);for(;u;z(b,B)){j=h[J=getchar()-49];R(0,0);K=j%v-k%v;I=j/u^k/u?j/u-(k/u+2)%3?1:-1:(K>0)-(K<0);O(a,A);O(b,B);O(h,5)P"%d\n",J+1);o(j)P"\n");o(k)P"\n%d\n",I);I>0?a[A++]=j:I?b[B++]=k:0;r(J);z(a,A);}}

Try it online!

-53-58 -65 bytes thanks to ceilingcat, really nice :)

This C version was written in order to check that the challenge was able to be solved even without using a modern programming language. This was pretty fun to make actually, since it was my first answer written in C. This answer was originally posted in order to announce a bounty for the first sub 500-bytes answer (Awarded to Arnauld for his JavaScript anwser).

A small explanation of this code:

  • u andv are constants (u is also used as the checking boolean at the end of a round in order to check if the game is finished)
  • h is the hand (5 cards chosen randomly withr()),a andb are the winning piles for Player 1 and 2,A andB are the number of cards in each pile, and the other variables are used as temporary values
  • o() prints a single card,O() prints a list of cards,R() generates a random card and checks recursively if the card is contained within l, adds -1 to the list otherwise,r() chooses a new random card for the hand, added at position n, by usingR() until the value is a positive number, andz() modifiesu if the game is finished
  • The main program retrieves the two cards chosen by each player, calculates the winner for this round, prints the required lines, adds a new card to the hand, and checks if the game is finished using botha andb
-5 extra bytes thanks to ceilingcat!

C (gcc),715685632632 627 bytes

#define y(x);}x(l,n)int*l;#define P;printf(u,v=11,h[5],a[99],b[99],A,B,i,j,k,I,J,K;oK,c,d;o(n){P"%c%c%d","FWS"[n/u],"ROYGBP"[n/v%6],n%v+2)y(O){for(i=0 P i<n?","+!i:"\n"),i<n;)o(l[i++])y(R){k=n?R(l+1,n-1),k^*l?k:-1:rand()%198;}r(n){for(h[n]=-1;R(h,5),h[n]<0;h[n]=k)u=66 y(z){for(i=0;I=l[i]/v,i<n;)for(j=i++;J=l[j]/v,K=l[n-1]/v,j++<n;j++<n;u*=I%6==J%6|I%6==K%6|J%6==K%6||c|d&&!c|c==d|!d)u*=I%6==J%6|I%6==K%6|J%6==K%6||Ic=I/6-J/6|J6,d=K/6-K/6&&I/6==J/6|I/6==K/6|J/6==KJ/6;}main(w){for(srand(&w);i<5;)r(i++);for(;u;z(b,B)){j=h[J=getchar()-49];R(0,0);K=j%v-k%v;I=j/u^k/u?j/u-(k/u+2)%3?1:-1:(K>0)-(K<0);O(a,A);O(b,B);O(h,5)P"%d\n",J+1);o(j)P"\n");o(k)P"\n%d\n",I);I>0?a[A++]=j:I?b[B++]=k:0;r(J);z(a,A);}}

Try it online!Try it online!

-53-5358 bytes thanks to ceilingcat, really nice :)

So it has been 4 or 5 days since I first posted this challenge, and there are still no answers. This was to be expected. I will therefore start a small bounty for the first person to find a sub-500 bytes answer (This requirement is based on an attempt I made with JS, not completely satisfied with it yet, so that's why I first post this C answer), and in the meantime, I wrote this C version was written in order to check that the challengecanwas able to be solved evenwith limited functionalitieswithout using a modern programming language. This was pretty fun to make actually! It's probably not perfect,you can probably simplify some of the conditions and loops, but this issince it was my first answer written in C, so I'm still proud of this. This answer was originally posted in order to announce a bounty for the first sub 500-bytes answer (Awarded to Arnauld for his JavaScript anwser).

C (gcc),715685632 bytes

#define y(x);}x(l,n)int*l;#define P;printf(u,v=11,h[5],a[99],b[99],A,B,i,j,k,I,J,K;o(n){P"%c%c%d","FWS"[n/u],"ROYGBP"[n/v%6],n%v+2)y(O){for(i=0 P i<n?","+!i:"\n"),i<n;)o(l[i++])y(R){k=n?R(l+1,n-1),k^*l?k:-1:rand()%198;}r(n){for(h[n]=-1;R(h,5),h[n]<0;h[n]=k)u=66 y(z){for(i=0;I=l[i]/v,i<n;)for(j=i++;J=l[j]/v,K=l[n-1]/v,j++<n;)u*=I%6==J%6|I%6==K%6|J%6==K%6||I/6-J/6|J/6-K/6&&I/6==J/6|I/6==K/6|J/6==K/6;}main(w){for(srand(&w);i<5;)r(i++);for(;u;z(b,B)){j=h[J=getchar()-49];R(0,0);K=j%v-k%v;I=j/u^k/u?j/u-(k/u+2)%3?1:-1:(K>0)-(K<0);O(a,A);O(b,B);O(h,5)P"%d\n",J+1);o(j)P"\n");o(k)P"\n%d\n",I);I>0?a[A++]=j:I?b[B++]=k:0;r(J);z(a,A);}}

Try it online!

-53 bytes thanks to ceilingcat

So it has been 4 or 5 days since I first posted this challenge, and there are still no answers. This was to be expected. I will therefore start a small bounty for the first person to find a sub-500 bytes answer (This requirement is based on an attempt I made with JS, not completely satisfied with it yet, so that's why I first post this C answer), and in the meantime, I wrote this C version in order to check that the challengecan be solved evenwith limited functionalities. This was pretty fun to make actually! It's probably not perfect,you can probably simplify some of the conditions and loops, but this is my first answer in C, so I'm still proud of this.

C (gcc),715685632 627 bytes

#define y(x);}x(l,n)int*l;#define P;printf(u,v=11,h[5],a[99],b[99],A,B,i,j,k,I,J,K,c,d;o(n){P"%c%c%d","FWS"[n/u],"ROYGBP"[n/v%6],n%v+2)y(O){for(i=0 P i<n?","+!i:"\n"),i<n;)o(l[i++])y(R){k=n?R(l+1,n-1),k^*l?k:-1:rand()%198;}r(n){for(h[n]=-1;R(h,5),h[n]<0;h[n]=k)u=66 y(z){for(i=0;I=l[i]/v,i<n;)for(j=i++;J=l[j]/v,K=l[n-1]/v,j++<n;u*=I%6==J%6|I%6==K%6|J%6==K%6||c|d&&!c|c==d|!d)c=I/6-J/6,d=K/6-J/6;}main(w){for(srand(&w);i<5;)r(i++);for(;u;z(b,B)){j=h[J=getchar()-49];R(0,0);K=j%v-k%v;I=j/u^k/u?j/u-(k/u+2)%3?1:-1:(K>0)-(K<0);O(a,A);O(b,B);O(h,5)P"%d\n",J+1);o(j)P"\n");o(k)P"\n%d\n",I);I>0?a[A++]=j:I?b[B++]=k:0;r(J);z(a,A);}}

Try it online!

-53-58 bytes thanks to ceilingcat, really nice :)

This C version was written in order to check that the challengewas able to be solved evenwithout using a modern programming language. This was pretty fun to make actually,since it was my first answer written in C. This answer was originally posted in order to announce a bounty for the first sub 500-bytes answer (Awarded to Arnauld for his JavaScript anwser).

deleted 13 characters in body
Loading
deleted 4 characters in body
Loading
deleted 64 characters in body
Loading
added 11 characters in body
Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp